Quote:
Originally Posted by noobie
by the way, earlier I said it is a bug but it might also be considered as a design issue.
here is the problem about the code:
when you call an async method, the process is handled by a worker thread from thread pool. as soon as the process is completed, the worker thread returns to pool and callback method is invoked in the "caller thread"
so if you invoke another async method/delegete within an async method/delegate, here is what happens sometimes:
if the first async method is completed and the worker thread returned to thread pool already when the inner (second) async method is finished, it tries to get first worker thread (for callback method). but by the time then, it might be used for another process since it is a thread pool.
|
That makes sense and all, but I did try executing the BeginInternalConnect from my own worker thread when the Dns resolve is signaled completed, and the results were the same. But I'm certain it has something to do with both async operations happening consecutively, because in cases where a resolve is not required, it doesn't throw exceptions.
I should also note, when I coded it to use the BeginConnect overload that takes a string and does a resolve on it's own, thereby eliminating my async Dns query, the problem is still present.
Just not sure how to go about fixing it. :P