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.
What you have seems perfectly clear to me. Moving the lambda to a separate function adds lines of code but no clarity.
I would probably write the first line as:
but I don’t know which way is generally preferred.