views:

139

answers:

2

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.

+1  A: 

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";
}
Justin Ethier
For now I'm really looking for something without any external dependencies, but an interesting option, so thanks.
ho1
A: 

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.

Matt Davis
Thanks, I think this is what I was thinking of, though since VB2005 don't support anonymous methods I can't use it for this project.
ho1