> I thought only the main thread can be used to create GUI elements reliably. 
> Isn't that true?

No. As long as you are using the latest version of Win32::GUI and a late perl 
(5.8.7 +) you can have any number of threads creating GUI objects (a separate 
message pump will be created in each thread - so when one thread/window is 
frozen becuase it's doing work, all other thread/windows will still work).

The big problem becomes when you want to share Win32::GUI objects (the handles) 
between threads - for some things you'll be OK, for others you may get burnt 
(this is a windows issue rather than Win32::GUI). The best solution is to use 
the Win32::GUI object in the thread that created it and use thread safe queues 
to communicate between threads.

You are also safe when other perl modules create threads (perl and C threads) 
and comunicate back to the thread with the Win32::GUI GUI. 

For some examples on how easy threading can be with Win32::GUI have a look at: 

Win32::GUI::ThreadUtils @ http://www.robmay.me.uk/win32gui

The module is flaged as experimental, but it will give a good intro. Has some 
examples of various threading models - boss/worker etc.

Cheers,

Jeremy.


> Octavian
> 
> ----- Original Message ----- 
> From: "Perl Rob" 
> To: 
> Sent: Thursday, November 06, 2008 6:52 PM
> Subject: [perl-win32-gui-users] Threads
> 
> 
>> Hi all,
>>
>>
>>
>> Am I susceptible to a crash if I create a Win32::GUI object (such as a
>> label) in one thread, then call methods on that object in another thread?
>>
>>
>>
>> Following is an example of what I mean. Notice that I'm passing the label
>> object as an argument to the entry point function of the new thread. This
>> seems to work, but I don't know if I should be doing it just because it
>> works:
>>
>>
>>
>> use strict;
>>
>> use Win32::GUI();
>>
>> use threads;
>>
>>
>>
>> my $main = Win32::GUI::Window->new
>>
>> (
>>
>>    -name => 'Main',
>>
>>    -text => 'Template Window',
>>
>>    -size => [300,300],
>>
>> );
>>
>>
>>
>> my $label = $main->AddLabel
>>
>> (
>>
>>    -text => 'I like the number 10',
>>
>>    -pos  => [10,10],
>>
>> );
>>
>>
>>
>> threads->create('countDown', $label);
>>
>>
>>
>> $main->Center();
>>
>> $main->Show();
>>
>> Win32::GUI::Dialog();
>>
>>
>>
>> sub countDown
>>
>> {
>>
>>    my $labelObject = shift;
>>
>>
>>
>>    for (my $i=9; $i>0; $i--)
>>
>>    {
>>
>>        $labelObject->Text("I like the number $i");
>>
>>        sleep(1);
>>
>>    }
>>
>> }
>>
>>
>>
>> Thanks,
>>
>> Rob
>>
>>
> 
> 
> --------------------------------------------------------------------------------
> 
> 
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's 
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great 
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the 
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> 
> 
> --------------------------------------------------------------------------------
> 
> 
>> _______________________________________________
>> Perl-Win32-GUI-Users mailing list
>> Perl-Win32-GUI-Users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
>> http://perl-win32-gui.sourceforge.net/ 
> 
> 
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Perl-Win32-GUI-Users mailing list
> Perl-Win32-GUI-Users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
> http://perl-win32-gui.sourceforge.net/

_________________________________________________________________
BigSnapSearch.com - 24 prizes a day, every day - Search Now!
http://clk.atdmt.com/UKM/go/117442309/direct/01/
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to