mail-archives/gtk-sharp-list/2007-January/007683.html

99 строки
4.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Gtk-sharp-list] Responsive Applications
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Responsive%20Applications&In-Reply-To=459FE27F.1050703%40homechoice.co.uk">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="007681.html">
<LINK REL="Next" HREF="007680.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Gtk-sharp-list] Responsive Applications</H1>
<B>Felipe Almeida Lessa</B>
<A HREF="mailto:gtk-sharp-list%40lists.ximian.com?Subject=%5BGtk-sharp-list%5D%20Responsive%20Applications&In-Reply-To=459FE27F.1050703%40homechoice.co.uk"
TITLE="[Gtk-sharp-list] Responsive Applications">felipe.lessa at gmail.com
</A><BR>
<I>Sat Jan 6 13:31:28 EST 2007</I>
<P><UL>
<LI>Previous message: <A HREF="007681.html">[Gtk-sharp-list] Responsive Applications
</A></li>
<LI>Next message: <A HREF="007680.html">[Gtk-sharp-list] Is it possible to create a button using the Glade-2 gui creater - when needing a button with a pango markup text?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7683">[ date ]</a>
<a href="thread.html#7683">[ thread ]</a>
<a href="subject.html#7683">[ subject ]</a>
<a href="author.html#7683">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>On 1/6/07, White Spirit &lt;<A HREF="http://lists.ximian.com/mailman/listinfo/gtk-sharp-list">wspirit at homechoice.co.uk</A>&gt; wrote:
&gt;<i> Matteo Bertozzi wrote:
</I>&gt;<i> &gt; Why OnButtonClick() Code Freeze the GUI?
</I>&gt;<i> &gt; and how i could correct it?
</I>&gt;<i>
</I>&gt;<i> The problem is here:
</I>&gt;<i>
</I>&gt;<i> &gt; Gtk.Application.Invoke (delegate {
</I>&gt;<i> &gt; Thread.Sleep(1800 + 3600);
</I>&gt;<i> &gt; button.Label = &quot;End Hard Work&quot;;
</I>&gt;<i> &gt; });
</I>
Yes, the problem is there.
&gt;<i> The code in the event handler is already running in the GTK thread.
</I>&gt;<i> Your code attempts to pass the code to the GTK thread from within the
</I>&gt;<i> GTK thread.
</I>&gt;<i>
</I>&gt;<i> Gtk.Application.Invoke is only used within threads other than the GTK
</I>&gt;<i> thread (because GTK# is not 'threadsafe'). So, if you had a thread
</I>&gt;<i> called mythread, once that thread was started you would use
</I>&gt;<i> Gtk.Application.Invoke to access GTK objects safely.
</I>
In fact, you can use Gtk.Application.Invoke everywhere. As you said,
he's already on the GTK's thread, so Gtk.Application.Invoke just
executes the code right away.
The problem, in fact, is that he is using Thread.Sleep in the GTK's
thread, so this blocks the UI. If this sleep is simulating some work
being done, it should be put on a different thread like this:
// UNTESTED
Thread worker = new Thread(delegate {
Thread.Sleep(1800 + 3600);
// We're on a different thread, Gtk.Application.Invoke is mandatory
Gtk.Application.Invoke(delegate {
button.Label = &quot;End Hard Work&quot;;
});
});
worker.Start();
--
Felipe.
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="007681.html">[Gtk-sharp-list] Responsive Applications
</A></li>
<LI>Next message: <A HREF="007680.html">[Gtk-sharp-list] Is it possible to create a button using the Glade-2 gui creater - when needing a button with a pango markup text?
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#7683">[ date ]</a>
<a href="thread.html#7683">[ thread ]</a>
<a href="subject.html#7683">[ subject ]</a>
<a href="author.html#7683">[ 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>