vb.net - Threading Exception: The number of WaitHandles must be less than or equal to 64 -
the title make easy find others having error. i'm new threading, giving me heck. i'm getting runtime error crashed cassini. code i'm maintaining developed website project in vs 2003 , converted vs 2008 website project.
important info:
- the number of objects in
manualevents
array 128 in case. products
array of strings- need support .net 2.0
for each product string in products if not product.trim().toupper().endswith("obsolete") calls += 1 end if next dim results(calls - 1) downloadresults 'dim manualevents(calls - 1) threading.manualresetevent '128 objects in case. dim manualevents(0) threading.manualresetevent manualevents(0) = new threading.manualresetevent(false) 'note: don't think work because not seen here, ' code being used populate , cache long list of products, ' each own category, etc. misunderstanding something? 'initialize results structures 'spawn background workers calls = 0 each product string in products if not product.trim().toupper().endswith("obsolete") dim result new downloadresults 'manualevents(calls) = new threading.manualresetevent(false) 'moved above each after declaration of variable result.params.product = product result.params.category = doctype 'result.manualevent = manualevents(calls) result.manualevent = manualevents(0) result.context = me._context results(calls) = result threading.threadpool.queueuserworkitem(addressof processsinglecategoryproduct, results(calls)) threading.interlocked.increment(calls) 'replaces below incrementation 'calls += 1 end if next threading.waithandle.waitall(manualevents) 'crashes here
thread helper function (for sake of completion)
public shared sub processsinglecategoryproduct(byval state object) dim drs downloadresults = ctype(state, downloadresults) dim adc new cadcwebservice(drs.context) drs.docs = adc.downloadadc(drs.params.category, drs.params.product) drs.manualevent.set() end sub
you don't need array of 128 manual events check completion of 128 threads.
create 1 manual reset event , plain integer starting @ 128. decrement integer using interlocked.decrement
@ end of processsinglecategoryproduct
, , signal event when count reaches zero:
if (interlocked.decrement(byref mycounter) = 0) myevent.set();
then declare 1 threading.manualresetevent
opposed array of them, , can call waitone
instead of waitall
on it, , done.
see usr's comment easier alternative in case have .net 4.
Comments
Post a Comment