The following code is common:
Work w = new Work();
w.Data = 42;
threadDelegate = new ThreadStart(w.DoMoreWork);
newThread = new Thread(threadDelegate);
newThread.Start();
I just wonder, why there must be a delegate to bridge the Thread and the Method to execute on that thread?
Could we just send the method name to the Thread directly?
As a string? Ewww. If not as a string, how would you propose telling the thread what to execute? A delegate is the idiomatic way of representing “something to execute with a particular signature” in .NET.
Note that you don’t need to use
new ThreadStartor use a separate variable. This works fine using method group conversions:Or if you won’t need all those variables:
EDIT: Note that as of .NET 4, it’s generally a better idea to use the Task Parallel Library for this sort of thing.