开发者

Threads in Web Application ASP.NET

I want to use threads in ASP.NET web application. Is it possible to use threads like we use in windows forms application? or what would be the best approach to handle different tasks on the same page which are very开发者_如何学编程 time consuming and all the task are inter dependent at the one point.

Thanks in advance.


If .NET 4.0 is an option, I suggest you take a look at the new Task class. Tasks can be short or long running and you can link tasks any way you like or have them run in parallel with no dependencies.


Starting new threads is painless.

Thread thread=new Thread(MethodName);
thread.IsBackground=true;
thread.Start();

If you can provide more details as to what you're looking to do, I may be able to help you come up with a solution.


You should be careful using multiple threads in an ASP environment. ASP is inherently multi-threaded already, in that it is processing multiple requests simultaneously -- unlike a desktop application that only has one user. Unless your web application has very few users, it's unlikely that you have unused cores. Creating extra threads in your ASP page could negatively impact the performance of other page requests.

There's an article on doing asynch processing in ASP here: http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

This article explains the concept of asynch pages in ASP and how to do it without negatively impacting other connections, using the asynch API specifically designed for ASP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜