[Gtk-sharp-list] How to show custom window and do the computation in the background

Maciej Pilichowski bluedzins at wp.pl
Sun Jun 27 13:13:30 EDT 2010


On Sunday 27 June 2010 17:58:44 Christopher David Howie wrote:

> The only thing you really have to worry about is if the Show() call
> happens after the Destroy() call.  But again, as you should be
> using Application.Invoke() to call Destroy(), the dialog cannot be
> destroyed until it is shown, since it is shown before control
> returns to the GLib main loop.
>
> Make sense?

Yes, but with the shift I described not such worry:

public void UpdateCorpusInfo()
{
	var dlg  = new ProgressDialog("My title");
	var thread = new Thread (new ParameterizedThreadStart 
			(doUpdateCorpusInfo));
	thread.Start(dlg);
}

private void doUpdateCorpusInfo(object _arg)
{
	var dlg = (ProgressDialog)_arg;

	try
	{
		Gtk.Application.Invoke (delegate{ dlg.Show(); });
		
		// loading data and refreshing GUI (via Invoke)

	}
	finally
	{
		if (dlg!=null)
			Gtk.Application.Invoke (delegate{ dlg.Destroy();});
	}
}

> I thought it already had an example of this... or maybe it was
> removed. I'm not sure.  But I do recall reading such an example on
> the Mono website a while ago.

There are examples, but all scattered all over the page, there is no 
section (task oriented). So it was (for me at least) get the big 
picture.

Cheers,


More information about the Gtk-sharp-list mailing list