[Mono-dev] Emedding mono: System.Windows.Form trouble

Robert Jordan robertj at gmx.net
Thu Mar 3 05:38:51 EST 2011


On 03.03.2011 11:09, Guy Sherman wrote:
> The program then continues on to process the main event loop of the C++ side
> of things.

It seems like you don't start WinForms' event loop machinery
at all. This is done by invoking Application.Run(Form) or
one of its overloads.

Of course, this won't fly if you already have another event
loop on your C++ side, but this is by design. You must start
start another UI thread with its own event loop, something
like that:

public class PluginHost
{
         private MainForm mainForm;

         public void Start()
         {
	    var thread = new Thread (delegate {
             	mainForm = new MainForm();
		Application.Run(mainForm);
	    });
	    thread.Start();
         }
}

Don't forget that cross-thread access must be synchronized
afterward, i.e. you can't access UI elements from another
thread (like the thread running your C++ event loop)
w/out using Control.BeginInvoke.

Robert



More information about the Mono-devel-list mailing list