I think in your first example. do you mean
QueueUserWorkItem( () => SendMessage(message) );
In your second paragraph, where does the s parameter come from? I think you mean
QueueUserWorkItem( s => {SendMessage((string)s);} , message );
Now these two both work the same, but
In the first case: the message parameter is copied from the scope of this DoStuff method and stored directly in the lambda expression as a closure. Lambda stores a copy of message .
In the second case: message sent to Queue , and the queue is saved (along with the lambda) until the lambda appears. it passed during the launch of lambda, lambda.
I would say that the second case is more programmatically flexible, since it theoretically allows you to later change the value of the message parameter before calling the lambda. However, the first method is easier to read and more protected from side effects. But in practice, both work.
Sanjay manohar
source share