views:

44

answers:

3

Hi Guys,

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.

A: 

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.

Brian Rasmussen
A: 

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.

o6tech
A: 

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.

Ragoczy