But of course I now have the question...

I thought you might ask, but there's no point in expending energy until required :)

Instead of passing a handle to the object back to the parent so that it can control it, try giving the parent a shared variable that indicates what it wants the child to do to the object.

Try this. The thing to look for is $sig, named badly by analogy. Note also the sleep 1. Without it the parent thread will end the process before the child has chance to get a timeslice, with the result that you will create a zombie, which is actually quite hard to do on Win32:

#!perl -slw use strict; use threads; use threads::shared; use Thread::Queue; use Win32::Process; use Win32; use Data::Dumper; ## A shared var to communicate progress between work thread and TK my $Q = new Thread::Queue; ## A shared var to control the child process. my $sig :shared = ''; sub work{ # save STDOUT open(my $STDOUT_ORIG, ">&", \*STDOUT) or die; # connect TO_CHILD_PROC with CHILD_PROC pipe(CHILD_PROC, TO_CHILD_PROC); # change STDOUT to TO_CHILD_PROC # --> STDOUT of child process is set to TO_CHILD_PROC and # this is connected via pipe with CHILD_PROC open(STDOUT, ">&", \*TO_CHILD_PROC); my $ProcessObj; Win32::Process::Create( $ProcessObj, "C:\\Perl32\\bin\\perl.exe", "perl child.pl", 1, NORMAL_PRIORITY_CLASS, "." )|| die "$! : $^E"; async { { $ProcessObj->Suspend if $sig eq 'Suspend'; $ProcessObj->Resume if $sig eq 'Resume'; $ProcessObj->Kill(-1) and return if $sig eq 'Kill'; Win32::Sleep 100; redo; } }->detach; # restore STDOUT open(STDOUT, ">&", $STDOUT_ORIG) or die; while( <CHILD_PROC> ) { chomp($_); $Q->enqueue( $_ ); } close( CHILD_PROC ); } threads->new( \&work )->detach; use Tk; use Tk::ProgressBar; my $mw = MainWindow->new; my $pb = $mw->ProgressBar()->pack(); my $repeat; $repeat = $mw->repeat( 100 => sub { while( $Q->pending ) { my $progress = $Q->dequeue; return unless $progress; $repeat->cancel if $progress == 100; $pb->value( $progress ); } } ); $mw->Button( '-text' => 'Cancel', '-command' => sub { $sig = 'Kill'; sleep 1; e +xit 0; } )->pack(); $mw->Button( '-text' => 'Suspend', '-command' => sub { $sig = 'Suspend'; } )->pack(); $mw->Button( '-text' => 'Resume', '-command' => sub { $sig = 'Resume'; } )->pack(); $mw->MainLoop;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: Suspend/Resume a process from Tk GUI in Windows XP by BrowserUk
in thread Suspend/Resume a process from Tk GUI in Windows XP by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.