react-social-login

The easiest way to integrate Social Login in your React Apps ...Checkout NPM

Wednesday, August 3, 2011

Starting a Thread targeting method with parameters

Lets say you want to start a thread. How would you do it?
Thread T1 = new Thread(new ParameterizedThreadStart(SomeMethodName));

Restriction imposed by .NET is that Method which T1 targets can have only one parameter of object type. Hence, above code will work only if method signature is:
public static void SomeMethodName(object o)

But what if I want to invoke a method like:
public static void xyz (int a, int b)  ???

Answer is to use delegates here and start thread as:
Thread T3 = new Thread(delegate() { xyz(3, 4); });
or
Thread T3 = new Thread(() => xyz(3, 4)); 

No comments :

Post a Comment

What are your thoughts on this post? Did you like it?