.net - Task.Factory.FromAsync and RegisterWaitForSingleObject - doesn't the latter kill the usefulness of the former? -


the problem can described following quote msdn:

the commandtimeout property ignored during asynchronous method calls such beginexecutereader.

googling around solution problem have stumbled upon number of posts suggesting using task.factory.fromasync in conjunction threadpool.registerwaitforsingleobject.

on 1 can here , here, albeit 2 discuss asynchronous web requests, rather sql commands. problem same - timing out asynchronous sql command/web request.

the suggested approach call task.factory.fromasync , threadpool.registerwaitforsingleobject wait or timeout on handle corresponding task.

i not understand here. async io method utilizing io completion port callback in order return result. when such io operation starts, calling thread returns thread pool reused other requests.

on other hand, according msdn:

the registerwaitforsingleobject method queues specified delegate thread pool

and

the wait thread uses win32 waitformultipleobjects function monitor registered wait operations.

which means blocks thread pool thread until our async io returns or timeout occurs. if understanding correct, having n async ios in progress going block , lock n thread pool threads if using technique.

but then, point in using async io under these circumstances? iocp goodness killed registerwaitforsingleobject.

on other hand, according this msdn blog, registerwaitforsingleobject optimizes wait, batching multiple handles same thread 1 call waitformultipleobjects, in turns limited respect amount of handles can wait on - namely 64.

so how many thread pool threads (b)locked if 65 async io requests made same thread in conjunction registerwaitforsingleobject per each request?

so how many thread pool threads (b)locked if 65 async io requests made same thread in conjunction registerwaitforsingleobject per each request?

two (for registerwaitforsingleobject calls) - each threadpool thread can handle 64 requests (technically, it's value of maximum_wait_objects, 64 in practice).

doesn't latter kill usefulness of former?

no. reduce it's effectiveness, since there pooling of threads in registerwaitforsingleobject, doesn't kill usefulness.

note that, in c# 5, typically use async/await support timeout handle instead. task.delay can used handle simply, or can make extension method using timer handle timeouts on task.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -