[Gtk-sharp-list] waiting for an asynchronous operation to finish

Ben Maurer bmaurer at ximian.com
Thu Sep 29 13:56:25 EDT 2005


On Wed, 2005-09-28 at 15:22 +0200, Jeroen Zwartepoorte wrote:
> So i've got a Gtk# program (VfsNodeView) that starts an asynchronous
> operation and then needs to wait for it to finish. How to do this?
> 
> The operation in question is Gnome.Vfs.Drive.Mount(). This starts a
> new GThread (in native C code) to perform the mount. I pass a callback
> handler that gets called when the operation has finished. I want my
> main thread/loop to wait until it has finished.
> 
> In C (gtkfilesystemgnomevfs.c in libgnomeui) this is accomplished by
> starting a new MainLoop in the main thread (MainLoop.Run()) and then
> quitting that mainloop from the callback handler. However, that
> approach either doesn't work in Gtk# or exposes a serious bug: i
> randomly get this crash: "*** glibc detected *** mono: double free or
> corruption" etc.
> 
> System.Threading.Thread has Suspend() and Resume() methods, but how do
> these interact with the GLib mainloop?

That would stop the thread completely. You don't want that. Basically
Suspend/Resume == bad.

What you want to do is this:

Drive.Mount (delegate (bool succeeded) {
	Application.Invoke (delegate {
		if (!succeeded)
			DisplayErrorDialog();
		else
			DoStuff ();
	});
});

-- Ben



More information about the Gtk-sharp-list mailing list