Hans Olsson
Hans Olsson

Reputation: 55049

Neat way of calling InvokeRequired and Invoke

I seem to remember seeing some neat way of calling InvokeRequired and Invoke to avoid repeating too much code in every event handler but I can't remember what that was.
So does anyone know a neat way of writing that code?

Preferably for VB.Net 2005.

Upvotes: 3

Views: 1179

Answers (2)

Matt Davis
Matt Davis

Reputation: 46052

The SO question here addresses this issue from a C# perspective, and any of the answers can probably be tailored to VB easily enough.

Although my answer wasn't the accepted one, I find using MethodInvoker anonymous method approach to be the most straightforward.

Hope this helps.

Upvotes: 1

Justin Ethier
Justin Ethier

Reputation: 134257

One way to streamline it is to use the method described in Roy Osherove's Blog (keep in mind it requires using a custom DLL):

[RunInUIThread]
protected virtual void DoSomeUIStuff()
{
  this.Text = "hey";
}

Upvotes: 1

Related Questions