mail-archives/gtk-sharp-list/2011-May/010697.html

104 строки
4.6 KiB
HTML
Исходник Постоянная ссылка Обычный вид История

2019-06-06 22:02:55 +03:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] Force UI Update?
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Force%20UI%20Update%3F&In-Reply-To=BANLkTinPaHqNMJdeNT1myZ5_3X9qj44%3D1g%40mail.gmail.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="010695.html">
<LINK REL="Next" HREF="010690.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] Force UI Update?</H1>
<B>Jim Orcheson</B>
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Force%20UI%20Update%3F&In-Reply-To=BANLkTinPaHqNMJdeNT1myZ5_3X9qj44%3D1g%40mail.gmail.com"
TITLE="[Gtk-sharp-list] Force UI Update?">jim at va3hj.ca
</A><BR>
<I>Tue May 3 07:27:24 EDT 2011</I>
<P><UL>
<LI>Previous message: <A HREF="010695.html">[Gtk-sharp-list] Force UI Update?
</A></li>
<LI>Next message: <A HREF="010690.html">[Gtk-sharp-list] labelling a vbox - possible?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#10697">[ date ]</a>
<a href="thread.html#10697">[ thread ]</a>
<a href="subject.html#10697">[ subject ]</a>
<a href="author.html#10697">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>Thanks, that works.
I have avoided a separate thread because the processing in
DoLongProcessing() would only take a long time for a very few users, and
they would want that processing to complete before interacting with the
program in another way. Therefore I am not too concerned that the code
is blocking.
If it does end up bothering people, I can always redo the code as a
separate thread.
Jim
On 02/05/11 10:03 AM, Michael Hutchinson wrote:
&gt;<i> On Sun, May 1, 2011 at 4:29 PM, Jim Orcheson&lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">jim at va3hj.ca</A>&gt; wrote:
</I>&gt;&gt;<i> I have a Gtk# application where the processing of a menu item may take
</I>&gt;&gt;<i> many seconds. I want to change the cursor to a Watch before the actual
</I>&gt;&gt;<i> processing takes place, and then change the cursor back to Arrow when
</I>&gt;&gt;<i> done. For example:
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> OnMenuItem(...)
</I>&gt;&gt;<i> {
</I>&gt;&gt;<i> DoSetupProcessing();
</I>&gt;&gt;<i> this.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch);
</I>&gt;&gt;<i> DoLongProcessing();
</I>&gt;&gt;<i> this.GdkWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Arrow);
</I>&gt;&gt;<i> }
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> With this code the watch cursor is never displayed because UI updating
</I>&gt;&gt;<i> normally only occurs during idle processing, which of course does not
</I>&gt;&gt;<i> occur until after OnMenuItem returns.
</I>&gt;&gt;<i>
</I>&gt;&gt;<i> Is there a way to force the update to display the watch cursor without
</I>&gt;&gt;<i> DoLongProcessing using a separate thread?
</I>&gt;<i> You could manually flush the UI event queue with
</I>&gt;<i> while (Gtk.Application.EventsPending ())
</I>&gt;<i> Gtk.Application.RunIteration ();
</I>&gt;<i> but your processing code will still be blocking the UI thread while
</I>&gt;<i> you're doing your processing, so if anything gets invalidated by an
</I>&gt;<i> external source it won't redraw.
</I>&gt;<i>
</I>&gt;<i> For a good user experience, you should really do the processing in a
</I>&gt;<i> thread, and probably show a modal dialog with a progress bar and a
</I>&gt;<i> cancel button. Your processing thread can update the progress bar
</I>&gt;<i> using Gtk.Application.Invoke to touch the UI thread.
</I>&gt;<i>
</I>&gt;<i> <A HREF="http://www.mono-project.com/Responsive_Applications">http://www.mono-project.com/Responsive_Applications</A>
</I>&gt;<i>
</I></PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="010695.html">[Gtk-sharp-list] Force UI Update?
</A></li>
<LI>Next message: <A HREF="010690.html">[Gtk-sharp-list] labelling a vbox - possible?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#10697">[ date ]</a>
<a href="thread.html#10697">[ thread ]</a>
<a href="subject.html#10697">[ subject ]</a>
<a href="author.html#10697">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">More information about the Gtk-sharp-list
mailing list</a><br>
</body></html>