-
private EventHandler<MyEventArgs> NameObscured1(IMyForm form)
-
{
-
return new EventHandler<NameObscured2>((sender, eventArgs) =>
-
{
-
form.TabControl.Enabled = false;
-
IAsyncResult iar = null;
-
Action bg = null;
-
bg = new Action ( () => {
-
NameObscured3((s) => {
-
form.StatusLabel.Owner.Invoke(new Action(() => {
-
form.StatusLabel.Text= s;
-
form.StatusProgressBar.Value +=2;
-
}));
-
return false;
-
});
-
NameObscured4(sender, eventArgs);
-
});
-
Action enableForm = () => { form.TabControl.Enabled = true; form.StatusProgressBar.Value = 0; };
-
AsyncCallback callback = (_) => { form.TabControl.Invoke(enableForm); bg.EndInvoke(iar); };
-
iar = bg.BeginInvoke(callback, null);
-
});
-
}
The question is… How can I make this more readable, and is it worth spending the time to do so?
Nesting lambdas to 4 deep cannot be a good idea, but honestly, factoring each one out to a method might actually make this code LESS readable IMO. In this case, it is just a damned shame that some things can be done cross threads in a Windows Forms application.
I’m guessing this is a sign that I am too tightly coupled and should have some kind of mediator which will then Invoke property updates on the correct thread, but I don’t have that now.
Moral of the story: don’t write nasty nested lambdas like me.