Recursive appeal: bad style?

Below is a pretty intimidating pattern, which I sometimes use as a lazy way to make a simple call. This code makes me feel a little guilty, although I'm not sure why. It's horrible? Reasonable? Are you going to explode on my face later?

public void myMethod(object args) { if (InvokeRequired) { Invoke(new MethodInvoker(delegate { myMethod(args); })); return; } //Do Stuff } 
+4
source share
2 answers

This is a very common way to make sure that a method is started using the UI thread synchronization context. There is nothing wrong.

(On the side of the note, this is an agreement in .NET to use pascal for methods , so I would change this to MyMethod Given that this question is about style, I think it's worth mentioning.)

+8
source

It's fine. All in one place. Easy to understand.

+1
source

All Articles