I’m developing a VS Package and I have this problem:
I have a Background-Thread which checks every few seconds for specific changes that have to be done. This includes changing the GUI of VS 2010, which works perfectly fine without an invoke for some reason.
Anyway if I try to open a new Form, it opens, but it doesn’t show anything, kind of crashes and doesn’t respond.
I’ve already tried Application.OpenForms[0].invoke( /* delegate to create the form */).
This works fine, but I don’t have an open form all the time.
I’ve also tried to create a System.Windows.Forms.Timer, but it doesn’t start in the first place.
Question: How can I get the correct GUI thread to invoke my Form?
or rather: How can I create a new Form from my background thread?
Store instance of SynchronizationContext.Current somewhere when your main application starts.
Once set up.
you can try following code in any other thread.
Where GuiContext is the stored instance of the SynContext.