From: Frazier, J. J. <Joe.Frazier@Peopleclick.com> - 2004-08-19 14:35:06
|
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;=20 # contruct GUI here -->=20 my $Window =3D new Win32::GUI::Window ( -name =3D> "Window", -topmost =3D> 1, -left =3D> 300, -dialogui =3D> 1, -top =3D> 400, -width =3D> 222, -addstyle =3D> WS_VSCROLL, -height =3D> 300, -text =3D> "Test", #-class =3D> $class, ); $Window->AddButton( -name =3D>"SomeButton", -top =3D> '30', -left =3D> '1', -text =3D> "TipTest", -tip =3D> "This is a Tip!", -width =3D> 150, -height =3D> 25, ); $Window->Show(); $Window->Enable(); $Window->Center(); my $commandQueue =3D Thread::Queue->new;=20 threads->new(sub { while (my $command =3D $commandQueue->dequeue) { eval $command; warn $@ if $@; } });=20 Win32::GUI::Dialog;=20 sub function { my $var =3D shift; sleep 5; print $var,"\n"; print "Pending Threads: ", $commandQueue->pending,"\n"; =09 } 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: Support@Peopleclick.com=20 > -----Original Message----- > From: per...@li...=20 > [mailto:per...@li...] On=20 > 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 >=20 > This model works quite well: -=20 >=20 > use win32::GUI; > use threads; > use Thread::Queue;=20 >=20 > # contruct GUI here -->=20 >=20 > my $commandQueue =3D Thread::Queue->new;=20 >=20 > threads->new(sub { > while (my $command =3D $commandQueue->dequeue) { > eval $command; warn $@ if $@; > } > });=20 >=20 > Win32::GUI::Dialog;=20 >=20 > sub SomeButton_Click { > $commandQueue->enqueue("&somefunction(\$with_vars_as_refs)"); > }=20 >=20 > __END=20 >=20 > You will have access in the thread to any variable created=20 > before. You may want to use a Timer to start the thread etc..=20 >=20 > Blair.=20 >=20 >=20 > > 1. When using threading with win32::gui, would/could I create a=20 > > thread for each gui component/object? For example, from my Master=20 > > loop, could I create a thread that held a Window and every button,=20 > > textfield, etc. contained inside the Window, while another=20 > thread held=20 > > a Dialog Box with all of it"s components (textfields,=20 > buttons, etc.)? > > 2. If I can, from where do I control the Show() method? I tried=20 > > performing this from the Master Loop, but it said, of=20 > course, that my=20 > > $Window didn"t exist. Then, I tried passing the Show() through the=20 > > thread (e.g. $sample_thread->$Window->Show();), but that=20 > didn"t work=20 > > either. >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 > digital self defense, top technical experts, no vendor=20 > pitches, unmatched networking opportunities. Visit=20 > www.blackhat.com _______________________________________________ > Perl-Win32-GUI-Users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users >=20 >=20 |