in reply to Re: Re: Re: Re: Re: Re: Re: returning from a thread ?
in thread returning from a thread ?
sub B_resetScan_Click # saves text file, stops thread, restarts thread +. { # open file for write - we want to overwrite the previous file with + the new one open(FOLDERLIST, ">".LTG::dialog::CONFIGFILE) or die "Can't create/ +overwrite file: $!\n"; print FOLDERLIST "#FORCE#\n"; # category ID foreach (0..$window->LB_forceFolder->Count()) { # add each element of the force folder after replacing backslash +es by forward slashes my $folder = $window->LB_forceFolder->GetString($_); while ($folder =~ /\\/){ $folder =~ s/\\/\//; } print FOLDERLIST $folder."\n"; } print FOLDERLIST "#BAN#\n"; # category ID foreach (0..$window->LB_banFolder->Count()) { # add each element of the ban folder my $folder = $window->LB_banFolder->GetString($_); while ($folder =~ /\\/){ $folder =~ s/\\/\//; } print FOLDERLIST $folder."\n"; } close (FOLDERLIST); # now stop the current scan thread # to do this, write in a file th_com.thd the value 0 #if (defined $thread) #{ # open (THREADCOM, ">".LTG::dialog::THREADCOM) or die "Can't crea +te/overwrite file: $!\n"; # print (THREADCOM,"0"); # close THREADCOM; # stop thread #} print "create thread\n"; my $run : shared = 1; $thread = threads->new(\<G::scanChange::monitor());# \<G::scanC +hange::monitor); print "Waiting 5 seconds while the thread runs\n"; sleep 5; print "Shutting down\n"; $run = 0; $thread->join; }
sub monitor { my @wantedF; # folders to be scanned my @bannedF; # banned folders not to be scanned if ( -e LTG::dialog::CONFIGFILE) { open(FOLDERLIST,LTG::dialog::CONFIGFILE) or die "can't open file +"; my $content = <FOLDERLIST>; my $addForce = 0; while ($content) { if ($content ne "\n") { $content =~ s/\n/ /; ($content =~/^\#FORCE\#/)?($addForce = 1):(($content =~/^\# +BAN\#/)?($addForce = 0):($addForce?push(@wantedF,$content):push(@bann +edF,$content))); } $content = <FOLDERLIST>; } close (FOLDERLIST); } #open (THREADCOM, ">".LTG::dialog::THREADCOM) or die "Can't create/ +overwrite file: $!\n"; #print THREADCOM "1"; #close THREADCOM; #my $active = 1; my $run : shared; while ($run) { # if ( -e LTG::dialog::THREADCOM) # { # open(THREADCOM,LTG::dialog::THREADCOM) or die "can't open fi +le THREADCOM"; # $active = <THREADCOM>; # print "active : $active \n"; # close THREADCOM; # } my %changes = LTG::scanChange::startScan(\@wantedF,\@bannedF,INC +_SUBDIRS); foreach my $k (keys %changes) { print "key : $k -> content : $changes{$k}\n"; } # update database here Sumith print "---while---\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning from a thread - here's the code...
by BrowserUk (Patriarch) on Aug 22, 2003 at 18:54 UTC | |
by Foggy Bottoms (Monk) on Aug 26, 2003 at 14:47 UTC |