VB.NET - QueueUserWorkItem Completion -


i have array sources() containing few web page links, go through grabproxies() function.

for each source in sources     threadpool.queueuserworkitem(new waitcallback(addressof grabproxies), source) next 

i use simple variable incrementing method check if sources finished or not. issue isn't efficient, half of time doesn't detect (probably because 2 threads finish @ exact same time or something?)

dim sources_counttemp integer private function grabproxies(source string) (...) if sources_counttemp = sources.count      console.writeline("finished!")  end if 

either way, it's not efficient way work. how can manage signal , complete small amount of code when finished?

edit: variable method un-efficient ran 8 runs of of long function (20-30 seconds before finishes) , 4/8 times worked. (using 15 threads)

edit 2: seems work more of time once used new random() on source array. means seems when time out issues etc happen makes not work much.

is there way maybe check if threadpool threads running? , if 0 running action? guessing here. if have idea on how should let me know.

i found solution! no idea why works realistically shouldnt make difference tested 10 times , 10 times worked!

replace sources_counttemp += 1 (or whatever kind of incrementation method use) with:

invoke(new methodinvoker(sub() sources_counttemp += 1))


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -