Problem :
Can somebody please clarify why we use ThreadStart?
new Thread (new ThreadStart (Update)).Start(); -Versus-
new Thread (Update).Start(); // Seems more straightforward
private void Update() { }
Solution :
Can somebody please clarify why we use ThreadStart?
You don’t have to. If you do, only you can say why…
Since C# 2, method groups (i.e. references to a method via its name) are implicitly convertible to delegates with the same signature. Since the Thread
constructor takes a ThreadStart
, you can pass it a method group with the same signature as ThreadStart
.
You don’t have to use it in your example.
ThreadStart is an object that holds a function that can be used to start a thread.
You’d use it for example if you have a list of functions which you want to start, put them in a list, and loop through them.