I have a following method
private void SetProcessDocumentStatus(string status)
{
var setStatusWith = new Action<string>(
statusValue => processDocumentStatusLabel.Text = statusValue);
if (processDocumentStatusLabel.InvokeRequired)
processDocumentStatusLabel.Invoke(
(MethodInvoker)(() => setStatusWith(status)));
else
setStatusWith(status);
}
From the above code, I am encapsulating action into setStatusWith
.
Should that action be refactored into another method as follows?
private void SetProcessDocumentStatusWith(string status)
{
processDocumentStatusLabel.Text = status;
}
private void SetProcessDocumentStatus(string status)
{
if (processDocumentStatusLabel.InvokeRequired)
processDocumentStatusLabel.Invoke(
(MethodInvoker)(() => SetProcessDocumentStatusWith(status)));
else
SetProcessDocumentStatusWith(status);
}
I am wondering if “Action” delegate should be used sparingly in code.