J
Jay
How do I stop execution of remaining sub procesures in a multithreaded app?
For example:
sub form_load
dim i as integer
for i = 1 to 5 '5 threads
dim ts as threadstart(addressof classname.procwhatever)
dim wthread as thread(ts)
classname.currentthread=wthread
whread.setapartmentstate(apartmentstate.sta)
wthread.name=i.tostring
wthread.start()
next
sub procwhatever 'executes at thread start
call proc1 '(may also be a function call)
if somecondition=true then
'need to stop thread from processing remaining subs (proc2, proc3)
end if
call proc2
if somecondition=true then
'need to stop thread from processing remaining subs (proc3)
end if
call proc3
end sub
sub proc1
'do stff here
end sub
sub proc2
'do stff here, etc.
end sub
sub proc3
'do stff here
end sub
So is somecondition is true in the procwhatever I need to stop execution of
the remaining subs but leave the app running. This app will end up a
windows service. I thought of just "Exit sub" however, sub1 might call
sub2. Sub2 may call sub55, sub 55 may call sub3, etc, etc. So I need to
end the processing and return the app to an idle state pretty much anywhere
in the code. Is it possible to tell the threads remaining operations to
stop? I still do need to keep the thread active but just stop execution of
remaining code. any thoughts?
end sub
For example:
sub form_load
dim i as integer
for i = 1 to 5 '5 threads
dim ts as threadstart(addressof classname.procwhatever)
dim wthread as thread(ts)
classname.currentthread=wthread
whread.setapartmentstate(apartmentstate.sta)
wthread.name=i.tostring
wthread.start()
next
sub procwhatever 'executes at thread start
call proc1 '(may also be a function call)
if somecondition=true then
'need to stop thread from processing remaining subs (proc2, proc3)
end if
call proc2
if somecondition=true then
'need to stop thread from processing remaining subs (proc3)
end if
call proc3
end sub
sub proc1
'do stff here
end sub
sub proc2
'do stff here, etc.
end sub
sub proc3
'do stff here
end sub
So is somecondition is true in the procwhatever I need to stop execution of
the remaining subs but leave the app running. This app will end up a
windows service. I thought of just "Exit sub" however, sub1 might call
sub2. Sub2 may call sub55, sub 55 may call sub3, etc, etc. So I need to
end the processing and return the app to an idle state pretty much anywhere
in the code. Is it possible to tell the threads remaining operations to
stop? I still do need to keep the thread active but just stop execution of
remaining code. any thoughts?
end sub