How to pass parameters to a method executing by a thread in c-sharpMany 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