Static News Archive

   (27-Mar-08 18:26)  Showing a dialog in response to a remoting event
If you have events being fired from your backend to your frontend using .net remoting, you sometimes may want to do something like show a dialog to the user.

Simple enough right?
Well - perhaps not...

Calling myForm.ShowDialog(); will throw a horrible exception as follows:

"The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone)."


My inital thoughts were to use the old form.InvokeRequired check to see if the current thread is the UI thread...
Unfortunately, this does nothing.

The solution that I found was both incredibly obscure, and very simple.
Before you call Application.Run, add the following line:

WindowsFormsSynchronizationContext.AutoInstall = false;

And that's it!

Post a comment     
(12-Oct-10 10:57)  Posted by Kim
Is that on the UI app or from the remoting app?

<-  (14-Mar-08 16:33)  Internet Radio... (21-Apr-08 23:37)  Simple Js problem an...  ->