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

Christopher David Howie me at chrishowie.com
Sun Jun 27 11:58:44 EDT 2010

On 06/27/2010 09:11 AM, Maciej Pilichowski wrote:
> I moved the last step -- showing progress dialog -- to the thread as 
> first step. This way I have a guarantee that altering dialog make 
> sense (because it is visible).

Ok.  You don't technically need to do this though.  And note that
Application.Invoke is asynchronous (it returns immediately, probably
before the delegate runs).  And as I mentioned before, the delegate will
not run until control of the main thread returns to the GLib main loop.
 So by doing it this way, you are actually going to delay showing of the
dialog by a very small fraction of a second.

However, most operations you are going to perform (such as setting a
progress bar's value) can be done whether the dialog is shown or not.
The changes will be visible once the dialog is shown.

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?

> Everything works fine (canceling dialog too), so it was quite 
> surprising for me, it was so easy ;-) Well, after you know what to do
> :-).

In programming, everything is easy when you know what to do.  ;)

> Just thinking -- would you like/mind to add this to the web page you 
> sent link to? As use case. If you don't have time I could write a 
> piece.

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.

Chris Howie

If you correspond with me on a regular basis, please read this document:

PGP fingerprint: 2B7A B280 8B12 21CC 260A DF65 6FCE 505A CF83 38F5


This document should be read only by those persons to whom it is
addressed.  If you have received this message it was obviously addressed
to you and therefore you can read it.

Additionally, by sending an email to ANY of my addresses you are
agreeing that I am, by definition, "the intended recipient," and that I
may do whatever I wish with the contents of any message you send me,
unless a pre-existing agreement prohibits me from so doing.

This overrides any disclaimer or statement of confidentiality that may
be included on your message.

More information about the Gtk-sharp-list mailing list