3

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.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116

2 Answers2

1

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
  • 131,333
  • 52
  • 229
  • 284
  • For now I'm really looking for something without any external dependencies, but an interesting option, so thanks. – Hans Olsson Apr 30 '10 at 13:45
1

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.

Community
  • 1
  • 1
Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • 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. – Hans Olsson Apr 30 '10 at 21:22