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     1260
  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));

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


Hope this will help someone....





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

Rate this article

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


Write your comment here.
Verification Code