[Gtk-sharp-list] Force UI Update?
m.j.hutchinson at gmail.com
Mon May 2 10:03:26 EDT 2011
On Sun, May 1, 2011 at 4:29 PM, Jim Orcheson <jim at va3hj.ca> wrote:
> I have a Gtk# application where the processing of a menu item may take
> many seconds. I want to change the cursor to a Watch before the actual
> processing takes place, and then change the cursor back to Arrow when
> done. For example:
> this.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
> this.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);
> With this code the watch cursor is never displayed because UI updating
> normally only occurs during idle processing, which of course does not
> occur until after OnMenuItem returns.
> Is there a way to force the update to display the watch cursor without
> DoLongProcessing using a separate thread?
You could manually flush the UI event queue with
while (Gtk.Application.EventsPending ())
but your processing code will still be blocking the UI thread while
you're doing your processing, so if anything gets invalidated by an
external source it won't redraw.
For a good user experience, you should really do the processing in a
thread, and probably show a modal dialog with a progress bar and a
cancel button. Your processing thread can update the progress bar
using Gtk.Application.Invoke to touch the UI thread.
More information about the Gtk-sharp-list