vb.net - how to start new thread as soon as previously thread gets finished? -
i have develop windows service copy files different servers. have task using multi-theading. have start 3-4 threads. whenever 1 threads finished have start new thread count of thread should remain 3 or 4. how apply check on ? please provide information on it.
this might give starting point. idea use blocking queue block on dequeue operation until item available. worker threads spin around infinite loop waiting items appear in queue. main thread enqueue items queue. following example uses blockingcollection class .net 4.0 bcl. if not available can implementation of blocking queue stephen toub's blog.
module example private m_queue blockingcollection(of string) = new blockingcollection(of string) sub main() dim threads(4) thread integer = 0 threads.length - 1 threads(i) = new thread(addressof consumer) threads(i).isbackground = true threads(i).start() next dim files ienumerable(of string) = getfilestocopy() each filepath string in files m_queue.add(filepath) next end sub sub consumer() while true dim filepath string = m_queue.take() ' process file here. loop end sub end module
Comments
Post a Comment