On Fri, Sep 26, 2008 at 3:31 AM, Mathias Tausig <[EMAIL PROTECTED]> wrote:
> Am 25. Sep 2008 um 08:14:03 -0400, schrieb Adam Tauno Williams:
>> On Thu, 2008-09-25 at 09:49 +0200, Mathias Tausig wrote:
>> > Am 24. Sep 2008 um 16:50:02 -0300, schrieb Pedro Guridi:
>> > >    I'm not sure if we are talking about the same thing.
>> > >    But what I'm saying, it's for the case when you have a long 
>> > > operation, or
>> > >    some long while/for, and because of that the gtk main loop will
>> > >    not be able to update the gui, or receive any event until the loop 
>> > > ends.
>> > >    To solve that you can add this inside the blocking loop (assuming that
>> > >    runs in the main thread than Gtk, that's the point after all) :
>> > >  while (Gtk.Application.EventsPending ())
>> > >          Gtk.Application.RunIteration ();
>> > Look at my code snippet in my inititial mail. That's exaclty what I am 
>> > doing in my DisplayPanel class, whenever I change the text. That's why I 
>> > consider this behaviour to be so weird
>> > >    Question.., I guess you are using these: "Thread.Sleep(3000)" for 
>> > > giving
>> > >    the gtk main thread a time to update the gui, I'm right?.
>> > >    if this is the case, try putting the code above instead of the
>> > >    "Thread.Sleep(3000);".
>> > The Thread.Sleep only exists in this short example function. In reality, a 
>> > longish and blocking function (a pinpad verification of a smartcard) is 
>> > executed.
>>
>> I haven't looked at the code in question, but rather than messing with
>> the loop wouldn't it be easier to put the pinpad verification into a
>> background thread and notify the main thread when success/failure
>> occurs?
>
> Maybe this would work. But I actually do want to understand, what the problem 
> is here.

Any operation in the GTK thread will block the GTK main loop until it
completes. If you expect an operation to take more than a few hundred
milliseconds, it should be performed asynchronously in another thread.

Your sample is clearly sleeping the GTK thread for 3 seconds. In these
three seconds, it cannot render. Clearing the event queue beforehand
doesn't change the fact that you're blocking it.

The code snippet
while (Gtk.Application.EventsPending ())
   Gtk.Application.RunIteration ();
is useful for clearing the event queue periodically from inside a
long-running loop. Nonetheless, if you do use this technique, you
should ensure that your outer loop hits this at a minimum of every few
hundred milliseconds for your application to remain responsive


-- 
Michael Hutchinson
http://mjhutchinson.com
_______________________________________________
Gtk-sharp-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to