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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |