Joseph,

I am having the same crashing problem as you.  However, I have a solution!  
Instead of using fork(), which is implemented using ithreads, just use ithreads.

The code below requires Perl 5.8 or higher.

### Begin Source

use Win32::GUI;
use threads;

use vars qw( $Main );

$Main = new Win32::GUI::Window(
     -name   => "Main",
     -text   => "Thread Test",
     -width  => 500,
     -height => 350,
     -left   => 100,
     -top    => 100,
);

$Main->AddButton(
     -name   => "Button",
     -text   => "Create Thread",
     -align  => 'center',
     -valign => 'center',
     -left   => 350,
     -top    => 10,
);

$Main->AddRichEdit(
     -name => "RichEdit",
     -left => 10,
     -top  => 50,
     -width => $Main->ScaleWidth-20,
     -height => $Main->ScaleHeight-70,
     -style => WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | 
ES_AUTOVSCROLL,
);

$Main->Show();

Win32::GUI::Dialog();

sub Main_Terminate {
    return -1;
}

sub Button_Click {
        threads->create(\&Do_Stuff)->detach;

        # Note:  by using detach() above, I am (falsely) assuming
        # that this thread will quit before the program does

        return 1;
}

# Call this with a thread
sub Do_Stuff {
        $Main->RichEdit->ReplaceSel("Child thread $$ started.\r\n");
        sleep(1);
        $Main->RichEdit->ReplaceSel("Child thread $$ exiting.\r\n");
        return;
}

### End Source


By the way, the bounce-back message you are getting from this list is just from 
some random list subscriber whose account does not allow the email to go 
through.

Trevor S Garside
[EMAIL PROTECTED]


> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 02, 2003 3:04 PM
> To: Garside, Trevor
> Cc: perl-win32-gui-users@lists.sourceforge.net;
> [EMAIL PROTECTED]
> Subject: RE: [perl-win32-gui-users] Unresponsive Window
> 
> 
> 
> The code is below.  This is the code I'm working with to try 
> and figure out
> how to get fork to work.  But it is pretty much the same as 
> my production
> code (same problem) except instead of going to sleep it does 
> something that
> takes several minutes to run, and the window has more objects 
> and looks
> nicer (but that isn't really important).  You can change the 
> value of the
> $howlong variable to decide how long it will sleep.  
> Basically just click
> the button and then do things to the window or on the 
> desktop.  At the very
> least you will get a memory error when you exit the program.  
> But sometimes
> you will also get it after the child process finishes.  I 
> found an example
> of a fork script that included several clean up (kill the 
> child process
> when it was done, etc...).  I used it to write a script that 
> would just
> call one child process and then quit, it worked fine until it 
> was added to
> a script that uses Win32::GUI.  There must be one additional clean up
> process that needs to be done, I just don't know what it is.
> 
> The reason that I didn't cc to the mailing list is because 
> the last two
> times I got an automated message from the admin of the mail 
> list that read
> the email was a possible Spam letter and that it would not be 
> sent.  But it
> was sent anyway.  I replied back asking why I got the message, but I
> haven't heard back from anyone.  I'll cc the mail list, 
> hopefully it was
> just a glitch.
> 

Reply via email to