Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Thread implementation for Win32::GUI

by ckant8 (Acolyte)
on Mar 27, 2013 at 11:26 UTC ( #1025681=note: print w/ replies, xml ) Need Help??


in reply to Re: Thread implementation for Win32::GUI
in thread Thread implementation for Win32::GUI

Please find below code. When i am running it window is freezing. i want to implement thread to not to freeze UI while background process is going on.

use strict; use warnings; use Net::Telnet; use Win32::API; use Win32::GUI(); my $main = Win32::GUI::Window->new( -name => 'Main', -width => 500, -height => 900, -text => 'Perl', -minsize => 500, 900, ); my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 8 +,); $main->AddLabel(-text => "Welcome ", -pos => [ 10, 10 ],); $main->AddLabel(-text => "Enter Host Name / IP : ", -pos => [ 10, 33 +], ); my $t= $main->AddTextfield( -name => 'tfResults', -text => "", -pos = +> [ 125, 30 ], -size => [ 100, 25 ], -tabstop => 1, ); my $my_but = $main->AddButton(-text => "Submit",-name => 'btQuery', -p +os => [ 235, 30 ],-size => [ 50, 25 ],); $main->Show(); Win32::GUI::Dialog(); sub btQuery_Click { my $txt1=$t->Text; my $telnet = new Net::Telnet ( Timeout=>1800, Errmode=>'die', + ); chomp $txt1; $telnet->open($txt1); $telnet->waitfor('/login: $/i'); $telnet->print('root'); $telnet->waitfor('/Password: $/i'); $telnet->print('dangerous'); $telnet->waitfor('/# $/i'); print "\nConnected to host :$txt1 "; $main->AddLabel(-text => " Enter custom cmd:",-pos => 100, 100 ,-siz +e => 250, 125 ,); my $t1= $main->AddTextfield(-name => 'tfResults2',-text => "",-pos = +> 130, 100 ,-size => 100, 25 ,); my $submit=$main->AddButton(-text => "Submit",-name => 'Unix_submit' +,-pos => 250, 100 ,-size => 50, 25 ,); sub Unix_submit_Click { } }


Comment on Re^2: Thread implementation for Win32::GUI
Download Code
Re^3: Thread implementation for Win32::GUI
by Corion (Pope) on Mar 27, 2013 at 11:50 UTC

    I recommend moving the actual work to be done into its own thread, most likely by using threads and Thread::Queue for the communication. Maybe the worker thread can signal to the main/UI thread by sending a window message.

      Thanks for the reply. Could you post some examples...plz

        I recommend the following setup:

        use strict; use threads; use Thread::Queue; my $remote_commands= Thread::Queue->new; my $status= Thread::Queue->new; # responses sub worker { $status->enqueue('Connecting to host'); require Net::Telnet; ... connect to host while (defined(my $cmd= $remote_commands->dequeue)) { $status->enqueue("Running [$cmd]"); $telnet->print($cmd); }; }; my $worker= threads->new( \&worker ); ... sub btQuery_Click { # ... send commands to queue $remote_commands->enqueue("cd /"); $remote_commands->enqueue("echo 'Hello World'"); ... };
Re^3: Thread implementation for Win32::GUI
by BrowserUk (Pope) on Mar 28, 2013 at 05:37 UTC

    If you add:

    use strict; use warnings;

    To the top of your program and then fix-up all the warnings you get; and then format your code so that it is readable; and post that.

    And then explain why you are defining functions within functions?

    And then explain what problems you are having adding threading?

    You might get some help.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.
      i have updated my code above same page. But i can't post actual script. Similar activities(ls,..) will do on host and print output in GUI. I am a beginner to Perl and Thread implementation. I have gone through the "http://search.cpan.org/~jdhedden/Thread-Queue-3.02/lib/Thread/Queue.pm", but i am confused how to start in my script. Please let me know is there any way to stop GUI hang. If you can help me, it will be a great help to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1025681]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-08-30 02:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls