你好点子,
我有一个 Tkx gui,它使用按钮运行批处理文件。批处理文件在不同的线程中执行,因为我希望 GUI 仍然可用。我想实现一个取消按钮来取消批处理文件的执行。
我尝试发送一个 Kill 信号,但它只会终止线程而不是批处理文件。下面是运行和取消子程序的代码。
哦,我不允许编辑批处理文件。
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();
}