- 论坛徽章:
- 0
|
问二的继续:http://bbs.chinaunix.net/thread-1270279-1-1.html
按stop可以暂停了,但是图形界面显然通道阻塞了(不可控)使用了多线程也无用。继续请教各位高手!
use Win32::GUI qw();
use threads;
#create main window
my $main = Win32::GUI::Window->new(
-name => 'Main',
-width => 410,
-height => 220,
-text => 'test',
-maxsize => [410, 220],
-minsize => [410, 220],
);
$Text_Informa=$main->AddTextfield(
-name => "Text_Informa",
-left => 10,
-top => 80,
-width => 383,
-height => 100,
-multiline => 1,
);
$main->AddButton(-name => 'btnDown', -text => 'Download',-left => 265, -top => 45,);
$btnStop=$main->AddButton(-name => 'btnStop', -text => 'Stop',-left => 338, -top => 45,);
# initialization
my $w = $main->ScaleWidth();
my $h = $main->ScaleHeight();
my $desk = Win32::GUI::GetDesktopWindow();
my $dw = Win32::GUI::Width($desk);
my $dh = Win32::GUI::Height($desk);
my $x = ($dw - $w) / 2;
my $y = ($dh - $h) / 2;
$main->Move($x, $y);
$main->Show();
Win32::GUI: ialog();
exit(0);
# window event handler
sub Main_Terminate {
-1; #terminate the message loop
}
sub Main_Resize {
$main->Resize($main->ScaleWidth - 20, $main->ScaleHeight - 40);
}
sub btnDown_Click {
my $thr = new threads(\&mythread );
$thr->detach();
}
sub mythread {
$pg = 9;
while($pg > 1){
$Text_Informa->Append( "$pg\n" ;
sleep 1;
if($control==1){last;}
$pg--;
}}
sub EndIt {my $con=shift; <>; $$con=1; return; }
#参考自[http://topic.csdn.net/t/20050503/16/3981999.html#[/url]
sub btnStop_Click { my $thr1 = new threads(\&mythread1); $thr1->join(); }
sub mythread1 {my $thd=new threads("EndIt",\$control); $thd->join(); }
[ 本帖最后由 3chi01 于 2008-9-21 13:59 编辑 ] |
|