.net - Threading Issue; how to implement properly? -


i have program have lots of tasks going on during splash screen. want make fast possible, , best solution have found web multithreading.

the problem don't know if i'm implementing them correctly, , i'm getting confused. i'm looking webcams on network, , have different protocol each brand. have different class each brand. want multiple brands @ same time speed up:

 public shared workingcamlist new list(of networksearch.camera)    public shared function findcameras(byref cameralist list(of networksearch.camera)) list(of networksearch.camera)      workingcamlist.clear()      dim brand1thread new system.threading.thread(addressof findfirstbrandcam)     dim brand2thread new system.threading.thread(addressof findsecondbrandcam)       brand1thread .start(workingcamlist)     brand2thread .start(workingcamlist)      'wait     brand1thread .join()     brand2thread .join()       return workingcamlist end function 

but instead of starting brand1 , brand 2 , me waiting until they're both done, join function(s) wait , go through them 1 one. they're both returning camera struct same list, i'm trying prevent race condition well. i'm okay creating 2 different lists , joining them.

how start 2 threads , wait until they're both done? i'm looking expand larger number of threads.

from msdn "thread.join() blocks calling thread until thread terminates, while continuing perform standard com , sendmessage pumping."

if you'd have both run @ same time , wait them both finished, create boolean each thread threaded functions can both see, in each function make sure set these booleans "true" once done, , loop until both of true.

' somewhere findfirstbrandcam , findsecondbrandcam can access , function can access dim finishedfindfirstbrandcam boolean = false dim finishedfindsecondbrandcam boolean = false   'in function (partial code) brand1thread .start(workingcamlist) brand2thread .start(workingcamlist)  'instead of .join() each thread until (finishedfindfirstbrandcam  , finishedfindsecondbrandcam )     application.doevents() loop  return workingcamlist 

the boolean method works small number of threads, expand n threads, track integer value, of threads increment when done (be sure use lock (synclock in vb.net) http://msdn.microsoft.com/en-us/library/3a86s51t.aspx, otherwise can have problems). loop until integer value equals number of threads needs have finished.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -