|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
End Processing in Multithreaded AppFor 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 Hi there,
In this case you would use a ManualResetEvent object. Get a thread that isn't busy to signal the event, then the event can acknowledge it and reset it again as it exits. e.g. ------- Thread 1 1) Create thread 2 3) Do stuff 4) Set event Thread 2 1) Do stuff 2) Check if event is set, if so go onto 3, otherwise loop 3) Reset event ------- If you are ever to have a reliable multi-threaded application it must use some form of synchronisation, these are really good and easy to use! Nick. Show quoteHide quote "Jay" <some***@somewhere.com> wrote in message news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... > 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 Thanks a lot Nick. Would you happen to know of examples illustrating this
type of behaviour? I've been searching the net however can't find much. Show quoteHide quote "NickP" <a@a.com> wrote in message news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... > Hi there, > > In this case you would use a ManualResetEvent object. > > Get a thread that isn't busy to signal the event, then the event can > acknowledge it and reset it again as it exits. > > e.g. > > ------- > > Thread 1 > > 1) Create thread 2 > 3) Do stuff > 4) Set event > > Thread 2 > > 1) Do stuff > 2) Check if event is set, if so go onto 3, otherwise loop > 3) Reset event > > ------- > > If you are ever to have a reliable multi-threaded application it must > use some form of synchronisation, these are really good and easy to use! > > Nick. > > "Jay" <some***@somewhere.com> wrote in message > news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >> 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 > > Hi Jay,
Ill knock an example together for you shortly. Nick. Show quoteHide quote "Jay" <some***@somewhere.com> wrote in message news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... > Thanks a lot Nick. Would you happen to know of examples illustrating this > type of behaviour? I've been searching the net however can't find much. > > > "NickP" <a@a.com> wrote in message > news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >> Hi there, >> >> In this case you would use a ManualResetEvent object. >> >> Get a thread that isn't busy to signal the event, then the event can >> acknowledge it and reset it again as it exits. >> >> e.g. >> >> ------- >> >> Thread 1 >> >> 1) Create thread 2 >> 3) Do stuff >> 4) Set event >> >> Thread 2 >> >> 1) Do stuff >> 2) Check if event is set, if so go onto 3, otherwise loop >> 3) Reset event >> >> ------- >> >> If you are ever to have a reliable multi-threaded application it must >> use some form of synchronisation, these are really good and easy to use! >> >> Nick. >> >> "Jay" <some***@somewhere.com> wrote in message >> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>> 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 >> >> >
http://nickpateman.m6.net/Files/MRE.zip
Here you go... Show quoteHide quote "NickP" <a@a.com> wrote in message news:eWNLNJUFHHA.960@TK2MSFTNGP04.phx.gbl... > Hi Jay, > > Ill knock an example together for you shortly. > > Nick. > > "Jay" <some***@somewhere.com> wrote in message > news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... >> Thanks a lot Nick. Would you happen to know of examples illustrating this >> type of behaviour? I've been searching the net however can't find much. >> >> >> "NickP" <a@a.com> wrote in message >> news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >>> Hi there, >>> >>> In this case you would use a ManualResetEvent object. >>> >>> Get a thread that isn't busy to signal the event, then the event can >>> acknowledge it and reset it again as it exits. >>> >>> e.g. >>> >>> ------- >>> >>> Thread 1 >>> >>> 1) Create thread 2 >>> 3) Do stuff >>> 4) Set event >>> >>> Thread 2 >>> >>> 1) Do stuff >>> 2) Check if event is set, if so go onto 3, otherwise loop >>> 3) Reset event >>> >>> ------- >>> >>> If you are ever to have a reliable multi-threaded application it must >>> use some form of synchronisation, these are really good and easy to use! >>> >>> Nick. >>> >>> "Jay" <some***@somewhere.com> wrote in message >>> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>>> 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 >>> >>> >> > > Thank you very much... I'll take a look. I appreciate it.
Show quoteHide quote "NickP" <a@a.com> wrote in message news:eIx89rUFHHA.1280@TK2MSFTNGP04.phx.gbl... > http://nickpateman.m6.net/Files/MRE.zip > > Here you go... > > "NickP" <a@a.com> wrote in message > news:eWNLNJUFHHA.960@TK2MSFTNGP04.phx.gbl... >> Hi Jay, >> >> Ill knock an example together for you shortly. >> >> Nick. >> >> "Jay" <some***@somewhere.com> wrote in message >> news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... >>> Thanks a lot Nick. Would you happen to know of examples illustrating >>> this type of behaviour? I've been searching the net however can't find >>> much. >>> >>> >>> "NickP" <a@a.com> wrote in message >>> news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >>>> Hi there, >>>> >>>> In this case you would use a ManualResetEvent object. >>>> >>>> Get a thread that isn't busy to signal the event, then the event can >>>> acknowledge it and reset it again as it exits. >>>> >>>> e.g. >>>> >>>> ------- >>>> >>>> Thread 1 >>>> >>>> 1) Create thread 2 >>>> 3) Do stuff >>>> 4) Set event >>>> >>>> Thread 2 >>>> >>>> 1) Do stuff >>>> 2) Check if event is set, if so go onto 3, otherwise loop >>>> 3) Reset event >>>> >>>> ------- >>>> >>>> If you are ever to have a reliable multi-threaded application it >>>> must use some form of synchronisation, these are really good and easy >>>> to use! >>>> >>>> Nick. >>>> >>>> "Jay" <some***@somewhere.com> wrote in message >>>> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>>>> 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 >>>> >>>> >>> >> >> > > no probs.
Show quoteHide quote "Jay" <some***@somewhere.com> wrote in message news:%23RmjrdWFHHA.420@TK2MSFTNGP06.phx.gbl... > Thank you very much... I'll take a look. I appreciate it. > > "NickP" <a@a.com> wrote in message > news:eIx89rUFHHA.1280@TK2MSFTNGP04.phx.gbl... >> http://nickpateman.m6.net/Files/MRE.zip >> >> Here you go... >> >> "NickP" <a@a.com> wrote in message >> news:eWNLNJUFHHA.960@TK2MSFTNGP04.phx.gbl... >>> Hi Jay, >>> >>> Ill knock an example together for you shortly. >>> >>> Nick. >>> >>> "Jay" <some***@somewhere.com> wrote in message >>> news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... >>>> Thanks a lot Nick. Would you happen to know of examples illustrating >>>> this type of behaviour? I've been searching the net however can't find >>>> much. >>>> >>>> >>>> "NickP" <a@a.com> wrote in message >>>> news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >>>>> Hi there, >>>>> >>>>> In this case you would use a ManualResetEvent object. >>>>> >>>>> Get a thread that isn't busy to signal the event, then the event >>>>> can acknowledge it and reset it again as it exits. >>>>> >>>>> e.g. >>>>> >>>>> ------- >>>>> >>>>> Thread 1 >>>>> >>>>> 1) Create thread 2 >>>>> 3) Do stuff >>>>> 4) Set event >>>>> >>>>> Thread 2 >>>>> >>>>> 1) Do stuff >>>>> 2) Check if event is set, if so go onto 3, otherwise loop >>>>> 3) Reset event >>>>> >>>>> ------- >>>>> >>>>> If you are ever to have a reliable multi-threaded application it >>>>> must use some form of synchronisation, these are really good and easy >>>>> to use! >>>>> >>>>> Nick. >>>>> >>>>> "Jay" <some***@somewhere.com> wrote in message >>>>> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>>>>> 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 >>>>> >>>>> >>>> >>> >>> >> >> > Hi Nak,
Beside you is Tom Leylan again active her, he was asking if we had ever heard something from Fergus, I told that even you did not, was I right? Cor Show quoteHide quote "NickP" <a@a.com> schreef in bericht news:ePLmwnWFHHA.2468@TK2MSFTNGP06.phx.gbl... > no probs. > > > "Jay" <some***@somewhere.com> wrote in message > news:%23RmjrdWFHHA.420@TK2MSFTNGP06.phx.gbl... >> Thank you very much... I'll take a look. I appreciate it. >> >> "NickP" <a@a.com> wrote in message >> news:eIx89rUFHHA.1280@TK2MSFTNGP04.phx.gbl... >>> http://nickpateman.m6.net/Files/MRE.zip >>> >>> Here you go... >>> >>> "NickP" <a@a.com> wrote in message >>> news:eWNLNJUFHHA.960@TK2MSFTNGP04.phx.gbl... >>>> Hi Jay, >>>> >>>> Ill knock an example together for you shortly. >>>> >>>> Nick. >>>> >>>> "Jay" <some***@somewhere.com> wrote in message >>>> news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... >>>>> Thanks a lot Nick. Would you happen to know of examples illustrating >>>>> this type of behaviour? I've been searching the net however can't >>>>> find much. >>>>> >>>>> >>>>> "NickP" <a@a.com> wrote in message >>>>> news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >>>>>> Hi there, >>>>>> >>>>>> In this case you would use a ManualResetEvent object. >>>>>> >>>>>> Get a thread that isn't busy to signal the event, then the event >>>>>> can acknowledge it and reset it again as it exits. >>>>>> >>>>>> e.g. >>>>>> >>>>>> ------- >>>>>> >>>>>> Thread 1 >>>>>> >>>>>> 1) Create thread 2 >>>>>> 3) Do stuff >>>>>> 4) Set event >>>>>> >>>>>> Thread 2 >>>>>> >>>>>> 1) Do stuff >>>>>> 2) Check if event is set, if so go onto 3, otherwise loop >>>>>> 3) Reset event >>>>>> >>>>>> ------- >>>>>> >>>>>> If you are ever to have a reliable multi-threaded application it >>>>>> must use some form of synchronisation, these are really good and easy >>>>>> to use! >>>>>> >>>>>> Nick. >>>>>> >>>>>> "Jay" <some***@somewhere.com> wrote in message >>>>>> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>>>>>> 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 >>>>>> >>>>>> >>>>> >>>> >>>> >>> >>> >> > > Hey Cor,
Unfortunately I haven't heard anything from Fergus in a long time. That was a funny time in the newsgroup! How are you? Nick. Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:%23E0M8zWFHHA.1216@TK2MSFTNGP05.phx.gbl... > Hi Nak, > > Beside you is Tom Leylan again active her, he was asking if we had ever > heard something from Fergus, I told that even you did not, was I right? > > Cor > > "NickP" <a@a.com> schreef in bericht > news:ePLmwnWFHHA.2468@TK2MSFTNGP06.phx.gbl... >> no probs. >> >> >> "Jay" <some***@somewhere.com> wrote in message >> news:%23RmjrdWFHHA.420@TK2MSFTNGP06.phx.gbl... >>> Thank you very much... I'll take a look. I appreciate it. >>> >>> "NickP" <a@a.com> wrote in message >>> news:eIx89rUFHHA.1280@TK2MSFTNGP04.phx.gbl... >>>> http://nickpateman.m6.net/Files/MRE.zip >>>> >>>> Here you go... >>>> >>>> "NickP" <a@a.com> wrote in message >>>> news:eWNLNJUFHHA.960@TK2MSFTNGP04.phx.gbl... >>>>> Hi Jay, >>>>> >>>>> Ill knock an example together for you shortly. >>>>> >>>>> Nick. >>>>> >>>>> "Jay" <some***@somewhere.com> wrote in message >>>>> news:OG4qM8KFHHA.964@TK2MSFTNGP05.phx.gbl... >>>>>> Thanks a lot Nick. Would you happen to know of examples illustrating >>>>>> this type of behaviour? I've been searching the net however can't >>>>>> find much. >>>>>> >>>>>> >>>>>> "NickP" <a@a.com> wrote in message >>>>>> news:%23xcsFwKFHHA.3304@TK2MSFTNGP05.phx.gbl... >>>>>>> Hi there, >>>>>>> >>>>>>> In this case you would use a ManualResetEvent object. >>>>>>> >>>>>>> Get a thread that isn't busy to signal the event, then the event >>>>>>> can acknowledge it and reset it again as it exits. >>>>>>> >>>>>>> e.g. >>>>>>> >>>>>>> ------- >>>>>>> >>>>>>> Thread 1 >>>>>>> >>>>>>> 1) Create thread 2 >>>>>>> 3) Do stuff >>>>>>> 4) Set event >>>>>>> >>>>>>> Thread 2 >>>>>>> >>>>>>> 1) Do stuff >>>>>>> 2) Check if event is set, if so go onto 3, otherwise loop >>>>>>> 3) Reset event >>>>>>> >>>>>>> ------- >>>>>>> >>>>>>> If you are ever to have a reliable multi-threaded application it >>>>>>> must use some form of synchronisation, these are really good and >>>>>>> easy to use! >>>>>>> >>>>>>> Nick. >>>>>>> >>>>>>> "Jay" <some***@somewhere.com> wrote in message >>>>>>> news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... >>>>>>>> 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 >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >> >> > > All you need to do is reverse your test of 'somecondition':
Sub procwhatever 'executes at thread start proc1() If Not somecondition Then proc2() If Not somecondition Then proc3() End Sub or, you could short-circuit it by: Sub procwhatever 'executes at thread start proc1() If Not somecondition Then proc2() If Not somecondition Then proc3() End If End Sub or even, with the original test: Sub procwhatever 'executes at thread start proc1() If somecondition Then Return proc2() If somecondition Then Return proc3() End Sub You have to be aware though that when you Return from procwhatever or procwhatever reaches the end of it's logic the thread will 'die'. Once all 5 threads have 'died' all you will have is an application with a form that is doing absolutely nothing. If you translate this to a service then you will end up with a service that is running but doing nothing. You need to start researching the mechanisms available for keeping threads alive (and responsive) and for terminating threads cleanly when a service needs to be stopped for any reason. Show quoteHide quote "Jay" <some***@somewhere.com> wrote in message news:%23x$QfqKFHHA.1248@TK2MSFTNGP03.phx.gbl... > 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
Re: Is VB.NET Stable?? To Aaron Kemp - Ahole Extrordinare
String to Byte & Vice Versa Best way to communicate from Desktop to SQL DB Re: Is VB.NET Stable?? Create Property on the fly Cross-thread operation not valid. catching close button Re: Is VB.NET Stable?? Transparent text box. Serialization problem |
|||||||||||||||||||||||