Hi Monks,

I have a Tkx gui which runs a batch file using button. The batch file is executed in a different thread, cause I want the GUI to still be usable. I want to implement a cancel button to cancel the execution of the batch file.

I tried sending a Kill signal but it will only terminate the thread and not the batch file. Below is the code. Thanks! Oh and I am not allowed to edit the batch file. =/

my $t1; sub runbutton{ $bar->g_grid(); $bar->start(); $t1 = threads->create(sub { local $SIG{'KILL'} = sub { threads->exit }; system("timer.bat"); }); $t1->set_thread_exit_only(1); my $start = time; my $end = time; while ($t1->is_running()) { $end = time(); $mytext = sprintf("%.2f\n", $end - $start); Tkx::update(); } $bar->stop(); $bar->g_grid_forget(); $b4->g_grid_forget(); } sub cancelbutton { $t1->kill('KILL')->detach(); }

In reply to Cancel a batch file ran by a thread from main by rezeile008

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.