ASP.NET应用程序中的多线程??? [英] Multithreading in ASP.NET app???

查看:50
本文介绍了ASP.NET应用程序中的多线程???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP.NET应用程序需要接受帖子中的数据并快速返回。

我已经添加了一个工作线程来唤醒并在
$ b之后异步保存数据收到$ b数据。但是,在我看来,IIS杀死了这个过程并且因为工作线程在我的主ASP.NET线程返回之后(任何人都知道某些人知道了吗?)。


您知道要实现此目的的设计模式吗?

My ASP.NET application needs to accept data from a post and return quickly.
I''ve added a worker thread to wake up and save data asynchronously after the
data is received. But, it appears to me that IIS kills the process and
thus the worker thread right after my main ASP.NET thread returns (anyone
know for certain?).

Do you know of a design pattern to accomplish this?

推荐答案

JV,


您必须弄清楚ASP.NET正在杀死进程的原因。
如果应用程序出现故障,ASP.NET确实有应用程序回收,有时,

如果内存消耗太高,它会回收这个过程。


我建议的是写一个能够执行此服务的服务

为您操作,然后使用像MSMQ这样的技术(通过

System.Messaging)向服务发送消息,然后处理

更新数据。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.gua rd.caspershouse.com


JV < OY ******** @ spammenot.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP10.phx.gbl ...
JV,

You have to figure out for what reason ASP.NET is killing the process.
ASP.NET does have application recycling if the app goes down, and sometimes,
if memory consumption is too high, it will recycle the process.

What I would recommend is writing a service that will perform this
operation for you, then using a technology like MSMQ (through
System.Messaging) to send a message to the service, which will then handle
the updating of the data.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
我的ASP.NET应用程序需求接受帖子中的数据并快速返回。我收到了一个工作线程,用于在收到数据后异步唤醒并保存数据。但是,在我看来,在我的主要ASP.NET线程返回之后,IIS终止了进程,从而杀死了工作线程(任何人都知道确定吗?)。

你知道一个设计模式来实现这个目标吗?
My ASP.NET application needs to accept data from a post and return
quickly. I''ve added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



你好,


检查一下...


/奥斯卡


//商业层......从ASP.NET网页调用...

public bool InitAsyncOperation(string someData)

{

try

{

//访问层

访问权限= Access.GetInstance(CurrentUser);


if(access.IsRunning)

{

返回false;

}

else

{

//首先我们做一些同步操作......

Wrapper wrapper = access.Validate(someData);


//然后我们踢异步...

MyDelegate d = new MyDelegate(<另一种方法......执行异步

操作...>);

As yncHelper.Execute(d,wrapper);

}

}

catch(exception ex)

{

if(ExceptionPolicy.HandleException(ex,CONTROLLER_EXCEPTION_POLICY))

throw;

}


返回true;

}


/// Class AsyncHelper

使用系统;

使用System.Reflection;

使用System.Threading;


namespace< SomeCompany>。< SomeApp> .Util

{

///< summary>

///从1.1版本的.NET Framework开始,SDK文档

///现在要小心要求代理人调用EndInvoke

///你打开了BeginInvoke,以避免潜在的泄密。

///这意味着你不能简单地发射并忘记从线程池中生成一个新的工作线程时没有

的风险

///创建一个对BeginInvoke的调用

///内存泄漏。

///

///使用模式不是针对

代表调用BeginInvoke,

///您将改为调用AsyncHelper.Execute,传递该委托并将

它的参数作为输入。

///请参阅: http://staff.develop.com/woodring 了解更多信息。

///< / summary>

///< example>

/// delegate void CalcAndDisplaySumDelegate(int a,int b);

/// CalcAndDisplaySumDelegate d = new

CalcAndDisplaySumDelegate(someCalc.Add);

/// AsyncHelper.Execute(d,2,3);

///< / example>

public class AsyncHelper

{

private static WaitCallback callback = new

WaitCallba ck(DynamicInvokeShim);


///< summary>

///采用委托和参数列表。执行

///目标的异步

调用(委托指向的Class.Method ..)。

///< ; / summary>

///< param name =" d">< / param>

///< param name =" args" ;>< / param>

///<作者> Oscar Thornell< / Author>

public static void执行(委托d,params object [] args )

{

ThreadPool.QueueUserWorkItem(回调,新的TargetInfo(d,args));

}


private static void DynamicInvokeShim(object obj)

{

TargetInfo targetInfo =(TargetInfo)obj;

targetInfo.Target.DynamicInvoke (targetInfo.Args);

}


class TargetInfo

{

内部只读委托目标;

内部只读对象[] Args;


内部TargetInfo(委托d,对象[] args)

{

目标= d;

Args = args;

}

}

}

}


" JV" < OY ******** @ spammenot.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP10.phx.gbl ...
Hi,

Check this out...

/Oscar

//Buisness layer...gets called from an ASP.NET web page...
public bool InitAsyncOperation(string someData)
{
try
{
//Access layer
Access access = Access.GetInstance(CurrentUser);

if(access.IsRunning)
{
return false;
}
else
{
//First we do some sync operation...
Wrapper wrapper = access.Validate(someData);

//Then we kick of the async...
MyDelegate d = new MyDelegate(<Another method...that performs the async
operation...>);
AsyncHelper.Execute(d, wrapper);
}
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, CONTROLLER_EXCEPTION_POLICY))
throw;
}

return true;
}


///Class AsyncHelper
using System;
using System.Reflection;
using System.Threading;

namespace <SomeCompany>.<SomeApp>.Util
{
/// <summary>
/// Starting with the 1.1 release of the .NET Framework, the SDK docs
/// now carry a caution that mandates calling EndInvoke on delegates
/// you''ve called BeginInvoke on in order to avoid potential leaks.
/// This means you cannot simply "fire-and-forget" a call to BeginInvoke
/// when spawning a new worker thread from the thread pool without the
risk
/// of creating a memory leak.
///
/// The usage model is that instead of calling BeginInvoke against a
delegate,
/// you would instead call AsyncHelper.Execute, passing that delegate and
it''s parameters as input.
/// See: http://staff.develop.com/woodring for further information.
/// </summary>
/// <example>
/// delegate void CalcAndDisplaySumDelegate( int a, int b );
/// CalcAndDisplaySumDelegate d = new
CalcAndDisplaySumDelegate(someCalc.Add);
/// AsyncHelper.Execute(d, 2, 3);
/// </example>
public class AsyncHelper
{
private static WaitCallback callback = new
WaitCallback(DynamicInvokeShim);

/// <summary>
/// Takes a delegate and a list of arguments. Performs asynchronous
invocation of the
/// target(the Class.Method the delegates points to..).
/// </summary>
/// <param name="d"></param>
/// <param name="args"></param>
/// <Author>Oscar Thornell</Author>
public static void Execute(Delegate d, params object[] args)
{
ThreadPool.QueueUserWorkItem(callback, new TargetInfo(d, args));
}

private static void DynamicInvokeShim(object obj)
{
TargetInfo targetInfo = (TargetInfo)obj;
targetInfo.Target.DynamicInvoke(targetInfo.Args);
}

class TargetInfo
{
internal readonly Delegate Target;
internal readonly object[] Args;

internal TargetInfo(Delegate d, object[] args)
{
Target = d;
Args = args;
}
}
}
}

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
我的ASP.NET应用程序需求接受帖子中的数据并快速返回。我收到了一个工作线程,用于在收到数据后异步唤醒并保存数据。但是,在我看来,在我的主要ASP.NET线程返回之后,IIS终止了进程,从而杀死了工作线程(任何人都知道确定吗?)。

你知道一个设计模式来实现这个目标吗?
My ASP.NET application needs to accept data from a post and return
quickly. I''ve added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



正如你所观察到的,你在Asp.Net中获得的多线程并没有太多的收获。


您可以创建一个Windows服务来接收由

Asp.Net应用程序发出的请求。请求可以通过多种方式传递。两个

最常见的是通过数据库和文件。

Eliyahu


" JV" < OY ******** @ spammenot.com>在消息中写道

新闻:Oi ************* @ TK2MSFTNGP10.phx.gbl ...
As you observed, you are not gaining much with multithreading in Asp.Net.

You can make a Windows service that will pick up requests made by the
Asp.Net application. The requests can be passed on in a number of ways. Two
most common ones are via a database and via files.

Eliyahu

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
我的ASP.NET应用程序需求接受帖子中的数据并快速返回。我收到了一个工作线程,用于在收到数据后异步唤醒并保存数据。但是,在我看来,在我的主要ASP.NET线程返回之后,IIS终止了进程,从而杀死了工作线程(任何人都知道确定吗?)。

你知道一个设计模式来实现这个目标吗?
My ASP.NET application needs to accept data from a post and return
quickly. I''ve added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



这篇关于ASP.NET应用程序中的多线程???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆