MultiThread in ASP.Net

How to use multithread in ASP.Net web form? Here is what I did:
private void MethodA(List<string> data)
//runing some stuff

//create a new thread to call another method
ThreadPool.SetMaxThreads(5, 5);
ThreadPool.QueueUserWorkItem(new WaitCallback(MethodB), paramsNeededByMethodB);

//keep running your original logic

private void MethodB(object parameters)
//cast to the correct data type
List<string> lstData = (List<string>)parameters;

//start your logic from here
1. MethodB must take the object as a parameter, no other data type is allowed.
2. Don't use too many threads. IIS will manage threads by itself. Here I set the max thread to 5.

No comments:

Post a Comment