You should try to join all your threads in Window_Terminate. As for gotchas for 5.8, you may notice that your thread processes vary in their time to start. I understand that this has been solved in 5.8.5 by using a new hashing algorithm. Because of this and since ActiveState always appear slow to release the latest binaries I am considering compiling perl 5.8.5 and using PAR instead of PerlApp (you don't have to go down the same route). Blair. Frazier, Joe Jr writes:
Ok, after finally getting 5.8.x(had to wait until I had the money for
PDK 5.x), I tried this. I used the following:
use win32::GUI;
use threads;
use Thread::Queue; # contruct GUI here -->
my $Window = new Win32::GUI::Window (
        -name   => "Window",
        -topmost => 1,
        -left   => 300,
        -dialogui => 1,
        -top    => 400,
        -width  => 222,
        -addstyle => WS_VSCROLL,
        -height => 300,
        -text   => "Test",
        #-class => $class,
);
$Window->AddButton(
-name =>"SomeButton",
-top => '30',
-left => '1',
-text => "TipTest",
-tip => "This is a Tip!",
-width  =>   150,
-height =>   25,
);
$Window->Show();
$Window->Enable();
$Window->Center(); my $commandQueue = Thread::Queue->new;
threads->new(sub {
        while (my $command = $commandQueue->dequeue) {
                eval $command; warn $@ if $@;
        }
}); Win32::GUI::Dialog; sub function
{
        my $var = shift;
        sleep 5;
        print $var,"\n";
        print "Pending Threads: ", $commandQueue->pending,"\n";
                
}
sub Window_Terminate
{
        for(1.. $commandQueue->pending)
        {
                $commandQueue->dequeue_nb();
        }
        undef $commandQueue;
        return -1;
}
sub SomeButton_Click {
$command

This works, but the problem is when I exit the program, I get this
"warning" printed to STDOUT:
d:\>gui100.pl
A thread exited while 2 threads were running.
Anyone know how stop this?  Also, now that I have 5.8, I hope to be able
to use threads more often.  Can anyone give any "gotchas" they have
found?
Joe Frazier, Jr.
Senior Support Engineer
Peopleclick Service Support
Tel:  +1-800-841-2365
E-Mail: [EMAIL PROTECTED]
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Blair Sutton
Sent: Thursday, June 24, 2004 10:41 AM
To: perl Win32::GUI Users
Subject: [perl-win32-gui-users] Working with threads This model works quite well: -
use win32::GUI;
use threads;
use Thread::Queue; # contruct GUI here --> my $commandQueue = Thread::Queue->new;
threads->new(sub {
        while (my $command = $commandQueue->dequeue) {
                eval $command; warn $@ if $@;
        }
}); Win32::GUI::Dialog;
sub SomeButton_Click {
        $commandQueue->enqueue("&somefunction(\$with_vars_as_refs)");
} __END You will have access in the thread to any variable created before. You may want to use a Timer to start the thread etc.. Blair.

> 1. When using threading with win32::gui, would/could I create a > thread for each gui component/object? For example, from my Master > loop, could I create a thread that held a Window and every button, > textfield, etc. contained inside the Window, while another thread held > a Dialog Box with all of it"s components (textfields, buttons, etc.)? > 2. If I can, from where do I control the Show() method? I tried > performing this from the Master Loop, but it said, of course, that my > $Window didn"t exist. Then, I tried passing the Show() through the > thread (e.g. $sample_thread->$Window->Show();), but that didn"t work > either.
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com _______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users




Reply via email to