in reply to Re: How to pass scrolled object to another thread
in thread How to pass scrolled object to another thread

Hi,

The Idea is the logging/status window should get update irrespective of any thing, These events happening at server are not triggered by my application and hence the update has to be asynchronous.
How can I update the GUI then?

Thanks,
Jai!
  • Comment on Re^2: How to pass scrolled object to another thread

Replies are listed 'Best First'.
Re^3: How to pass scrolled object to another thread
by BrowserUk (Patriarch) on Mar 19, 2011 at 07:10 UTC
    How can I update the GUI then?

    Here's one way:

    #! perl -slw use strict; use threads; use Thread::Queue; use Tk::Listbox; my $Q = new Thread::Queue; ## start a thread monitoring events async { ## Simulate asynchronous events with random sleeps while( sleep 1+rand 3 ) { ## When an event happens, Q it to the GUI thread. $Q->enqueue( "Event " . time ); } }->detach; my $mw = MainWindow->new; my $lb = $mw->Listbox()->pack; # 10 times per second my $repeat = $mw->repeat( 100 => sub { ##check to see if there are any events in the queue while( $Q->pending ) { ## if there are, grab them my $event = $Q->dequeue; ## adde them to the end of the listbox $lb->insert( 'end', $event ); ## and make sure the latest is visible. $lb->see( 'end' ); } }); $mw->MainLoop;

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks a ton for your help. This solution worked.
      Jai