http://qs321.pair.com?node_id=124947


in reply to Re: Re: Re:(wog) Win32::Gui + Threading?
in thread Win32::Gui + Threading?

What you probably should do is send a "special" message to the forked process (like you would send URLs, etc.) that will cause it to exit.
  • Comment on Re: Re: Re: Re:(wog) Win32::Gui + Threading?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re:(wog) Win32::Gui + Threading?
by Flame (Deacon) on Nov 13, 2001 at 03:45 UTC
    I've tried this (based upon several examples... I really still don't understand what most of this is doing...):
    pipe(FROM_P, TO_C) or die "pipe: $!"; select(((select(TO_C), $| = 1))[0]); if (!(my $pid = fork)){ close(TO_C); #close(FROM_C); my $running = 1; while(my $line = <FROM_P>) { Win32::GUI::MessageBox(0,"Child Pid $$ just read this: $line","G +MS Alert"); chomp($line) if($line =~ m/\n$/o); if(lc($line) eq 'exit'){ Win32::GUI::MessageBox(0,"Exit","GMS"); sleep(20); #To allow time to read the MessageBox... if it eve +r comes up... exit; } } }


    Later on, these two subs deal with the exiting of the main program:
    sub GMSMain_Terminate { defined(my $win = $Win32::GUI::Loft::window{GMSMain}) or return(1); print TO_C 'exit'; return(-1); } sub mnuFileExit_Click { defined(my $win = $Win32::GUI::Loft::window{GMSMain}) or return(1); print TO_C 'exit'; return(-1); }


    When running it, however, I can exit part of it (the gui part) but it remains visible and perl itself keeps running. There is no message box popping up from the other process either.

    I'm probably making a rather stupid mistake, so please point it out if I am.


    -----BEGIN GEEK CODE BLOCK-----
    Version: 3.12
    GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
    PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
    ------END GEEK CODE BLOCK------
    Translate

    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS

      Your problem is probably derived from trying to use the GUI from two threads. Don't do that. In your case what is probably happening is that when the forked process trys to pop-up its message box, the Win32::GUI event loop isn't running (since it just exited) so nothing happens.

      I advise against using Win32::GUI from multiple threads because Win32::GUI stores it's data in shared (not-thread-specific) variables (at the C level), so race conditions could easily cause crashes if you do not restrain from using it in only one thread.

      update: I have neglected to give an explanation as to why perl sticks around. I cannot think of a reason for it to not terminate after 20 seconds, unless Win32::GUI::MessageBox blocks, which would explain it.

        It still behaves the same with this code:
        pipe(FROM_P, TO_C) or die "pipe: $!"; select(((select(TO_C), $| = 1))[0]); if (!(my $pid = fork)){ close(TO_C); my $running = 1; while(my $line = <FROM_P>) { #Win32::GUI::MessageBox(0,"Child Pid $$ just read this: $line"," +GMS Alert"); chomp($line) if($line =~ m/\n$/o); if(lc($line) eq 'exit'){ exit; } } }


        So I don't think it's caused by the messagebox.


        -----BEGIN GEEK CODE BLOCK-----
        Version: 3.12
        GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
        PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
        ------END GEEK CODE BLOCK------
        Translate

        "Weird things happen, get used to it."

        Flame ~ Lead Programmer: GMS