The first and third calls are the exact same thing. Regarding these other two:
//Thread whee = new Thread((ThreadStart)delegate { someObject.Start(); });
//or, using a lambda expression,
Thread whee = new Thread(() => someObject.Start());
Thread whoo = new Thread(someObject.Start);
In the first one, you create a delegate that closes over (or captures) the someObject
variable. When the thread calls your delegate, it will evaluate which object the variable points to, and call Start
on it.
In the second one, someObject
is eagerly evaluated.
Thread whee = new Thread(() => someObject.Start());
Thread whoo = new Thread(someObject.Start);
someObject = someOtherObject;
whee.Start();
whoo.Start();
If you assign a new object to your someObject
variable before starting the threads, you'll notice that:
- the first thread calls
Start
on someOtherObject
, because the closure variable was lazily-evaluated.
- the second thread calls
Start
on the original instance someObject
pointed to, because the variable was eargerly-evaluated.