[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 12:03:34 EDT 2010


On 06/27/2010 11:58 AM, Christopher David Howie wrote:
> 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.

And, actually, I should have also noted that the dialog will be shown at
the point that the delegates run, which I explained after this
paragraph.  Basically, in your click event handler (or whatever) you
will probably be doing something like this:

----------8<----------
var dialog = new ProgressDialog();

new Thread(delegate() {
   // This is where you would do your actual work.
   for (int i = 0; i < 1000; i++) {
      Application.Invoke(delegate { dialog.Progress = i / 1000d; });
      Thread.Sleep(100);
   }

   Application.Invoke(delegate { dialog.Destroy(); });
}).Start();

// It is *impossible* for any of the invoked delegates to be run
// here, because this method is running on the GLib main loop thread.

dialog.Show();
----------8<----------

Note that if you are really concerned (which you shouldn't be) then you
can also do this instead:

----------8<----------
var dialog = new ProgressDialog();
var thread = new Thread(delegate() { ... });

dialog.Show();
thread.Start();
----------8<----------

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers

If you correspond with me on a regular basis, please read this document:
http://www.chrishowie.com/email-preferences/

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

------------------------------------------------------------------------
                    IMPORTANT INFORMATION/DISCLAIMER

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