tags:

views:

29

answers:

2

I have main window with button "open file". On clicking file selector dialog shows up and then file is loaded. I would like to show progress dialog while loading the data. However when I call Run

dlg.Run();
load_data(); // not executed

the execution stops there (I have to close the dialog to load the data), if I call Show

dlg.Show();
load_data();

then loading is done, but the dialog does not show up.

So, how to show modal, progress dialog and in meantime load the data?

Note: this question is only about showing the progress dialog, NOT updating the progressbar widget.

A: 

Ok, I asked on gtk# mono newsgroup and thanks to Chris Howie I finally managed to accomplish the task.

In short -- because maybe someone will also fall into this:

  • you create a dialog
  • you create a task
  • in the newly created task you show the dialog, you do the computation (and refresh the dialog), and you destroy the dialog

Because the dialog is modal you don't even have to worry about waiting for the task to complete -- it is already done by Gtk#.

macias
+1  A: 

If you just want to show the UI and then load the data, without processing events, the following will do the trick:

while (Gtk.Application.EventsPending ())
    Gtk.Application.RunIteration ();

You can put that in a method "FlushEvents" and then call that after you show the dialog and you can also run it every once in a while as you load the data to let the user click on cancel.

In practice, you might want to either use a thread or push events, or load progressively in an idle handler. See this document for more information:

http://www.mono-project.com/Multi-threaded_GtkSharp_Programing_and_Keeping_your_Application_Responsive

miguel.de.icaza
Thank you very much. Since I already wrote it I won't change my code now, but it is good to know there are other approaches.
macias