I'm curious when a piece of code should be its own method or just left alone. This came up when I was creating a "work item" from the thread pool. When passing the argument to the "WaitCallback" object, I would argue that if the code that will run will ONLY run when this thread is being run, then it's OK to wrap the code inside of an Action delegate. If other places need to run this same code, then I understand separating it into a new method.
So, for example, what's better practice?
This --
ThreadPool.QueueUserWorkItem(new WaitCallback((state) =>
{
Contract.SaveContract(Customer);
pushResultNotification = DoPushContact();
MyDispatcher.BeginInvoke((Action)(() => actionNotification.CompleteAction()), null);
}));
Or this --
ThreadPool.QueueUserWorkItem(new WaitCallback(DoStuff));
private void DoStuff(object state)
{
Contract.SaveContract(Customer);
pushResultNotification = DoPushContactToGp();
MyDispatcher.BeginInvoke((Action)(() => actionNotification.CompleteAction()), null);
}