What do i create at thread with a function with parameters?
Thread t = new Thread(new ParameterizedThreadStart(fetchQuotes(cp)));
void fetchQuotes(SomeObject obj)
{
[DoSomething With SomeObject]
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The easiest approach here is to use a closure over the non-parameterised (
ThreadStart) signature:This is static-checked for correctness at compile-time, and convenient (you can pass any number of parameters, for example).
The other approach is to pass
objectas the parameter (ParameterizedThreadStart):here we are passing
object, so not type-checked at compile time. “braindead” errors will only surface at runtime.