In a multi-threaded application, what is the performance impact of writing something like this:
TestClass t = new TestClass();
ThreadPool.QueueUserWorkItem(x=>DoSomething(t));
Is there any difference if i write it like this:
TestClass t = new TestClass();
ThreadPool.QueueUserWorkItem(x=>{
TestClass t2 = x as TestClass;
DoSomething(t2);
}, t);
And while im at it how about this:
TestClass t = new TestClass();
Action<TestClass> someAction = DoSomething;
someAction.BeginInvoke(t, asyncResult=>{
Action<TestClass> a = asyncResult.State as Action<TestClass>;
a.EndInvoke(asyncResult);
}, someAction);
In a somewhat related question, do all these pretty much do the same thing under the hood?