User Id :    Password :      New Member   Forgot Password  
 
How to pass parameters to a method executing by a thread in c-sharp
Description How to pass parameters to a method executing by a thread in c#.   No. of Views     1211
  Rating     0
Author Najmul Hoda   Posted On     08 Feb 2014
Tags C#,.NET Frameworks,C# : How To    

Sample Code   Download Code

Many times we need to execute methods in different threads for muti-tasking and  to improve application  performance. In some situation these methods need parameters to be passed in them.

 

Here is the codesnippet for executing a method in a thread with one or mutiple params.

 


public void ParameterisedThreadExample()
{
string userName = "najmul";
string userPwd = "najmul123#"
var TaskId = 101;

Thread thread = new Thread(() => LongRunningProcess(UserName,UserPwd,TaskId));
thread.Start();
}

private void LongRunningProcess(string UserName, string UserPwd, int TaskId)
{
	// do something
}

 

Hope this will help someone....

 

Thanks

 

 

About Author

About Author He is a team lead, having 8+ years of experience. He loves writing technical article for .Net developers. Najmul Hoda
No Photo
 
Country United States
Company BirlaSoft
Home Page http://www.magixchat.com

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code