user3267925
user3267925

Reputation: 69

Difference between Thread(method) and Thread(new ParameterizedThreadStart(method))

Whats the difference between the below two pieces of code?

Foo parameter = // get parameter value
Thread thread = new Thread(new ParameterizedThreadStart(DoMethod));
thread.Start(parameter);

Foo parameter = // get parameter value
Thread thread = new Thread(DoMethod);
thread.Start(parameter);


private void DoMethod(object obj)
{
    Foo parameter = (Foo)obj;
    // ...
}

Upvotes: 2

Views: 63

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292425

There's no difference. The compiler implicitly converts new Thread(DoMethod) to new Thread(new ParameterizedThreadStart(DoMethod)). Implicit conversion of a method group to a delegate with a compatible signature was introduced in C# 2; before that, you had to use the explicit form.

Upvotes: 3

Related Questions