What is the difference between the two piecees of code below. will there be any issues using the second one.
Scenario 1
private void Log(Exception e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Log), e);
}
private void Log(object obj)
{
Exception e = (Exception)obj;
Logger.Log(e);
}
Scenario 2
private void Log(Exception e)
{
ThreadPool.QueueUserWorkItem(
(obj) =>
{
Logger.Log(e);
});
}
In scenario 2, I am not passing the exception in as a paramter to the ThreadPool. How does the thread marshalling of the exception object occur? Will there be any problems? What are the limitations of doing this if any? The big advantage is that you can pass in any number of parameters very easily.