> I am encountering a challenge while using WaitAny to detect when any
> of my async processes have finished.
[quoted text clipped - 10 lines]
> again) - the same async process complete re-fires the same async item
> I just processed.
Things I don't understand about your question:
* Why are your arrays, ia_WaitHandles and la_AsyncResults, being
initialized to hold one fewer elements than you intend to put in them? In
this case, those arrays appear to be initialized to only a single element
long.
* Given the above, why does this line not generate an exception at
run-time, seeing how it attempts to set the second element in an array
that's only 1 element long:
ia_WaitHandles(1) =
iobj_ReturnGTISDataSet_AsyncResults.AsyncWaitHandle
* Regardless, why do you hard-code the array index for the handle in
the above line of code, rather than using li_IX as you do elsewhere?
And finally, this statement in your post:
> If have also tried to use the AutoResetEvent in the WaitAny event --
> But I can figure out how to have the methods being executed
> asynchronously in my class object to call the Set method on the
> AutoResetEvent to trigger my main thread to continue.
Even if I replace "I can figure" with "I can't figure" to try to make it
make more sense, I don't understand the statement. All you need to do is
pass an event handle you create to the delegate doing the work somehow.
Passing parameters to delegates isn't hard, so if you're having trouble
doing this, you should be more specific about what problem it is you have.
All that said, it seems to me that the most direct way to fix the code
you've got would be to just not wait on handles that have already
completed. You should be doing this anyway, because once you call
EndInvoke, the wait handle you've put into the array is not guaranteed to
be valid. But beyond that, not waiting on a wait handle that's always
been completed is the obvious solution to not having to deal with the wait
handle remaining signaled.
An alternative solution would be to simply reset the event handle manually
yourself after it's signaled. But as I mentioned above, after calling
EndInvoke you are not guaranteed to have a valid event handle, and so
that's not a solution you should choose. As an alternative to the
alternative, you could just create a dummy WaitHandle (manual or
auto-reset, it doesn't matter) that never gets set and replace the one you
got from the IAsyncResult object with the dummy one, after that
IAsyncResult gets signaled. IMHO, that solution would be a hack and
inappropriate in any well-written code, but it would work as well.
Pete