asp.net - More than one await in HttpTaskAsyncHandler -
httptaskasynchandler nice base-class making async http-handlers in asp.net 4.5 wonder how runtime handles more 1 await statement in processrequestasync.
public class callbackhandler : httptaskasynchandler { public override async task processrequestasync(httpcontext context) { int value1 = await task.factory.startnew(() => 1); int value2 = await task.factory.startnew(() => 2); int value3 = await task.factory.startnew(() => 3); context.response.write(value1 + value2 + value3); } public override bool isreusable { { return true; } } }
is iis thread being put on hold 3 times? how test/see this? better wrap 3 awaits in asyn method?
edit: concerned code take iis-workerthread 4 times handle request. if wrap in async method - performe better?
this diagram explaining difference between sync , asyn page processing in asp.net. afraid example result in 3 threads being started main worker thread (pink boxes on diagram) , thereby adding overhead.
iis -> task1 tp -> iis -> task2 tp -> iis -> task3 tp -> iis
(task switching main iis wt 4 times)
or compiler smart passes continuation on 1 task next, , returning main thread after 3 tasks done.
iis -> task1 tp -> task2 tp -> task3 tp -> iis
(task switching main iis wt 1 time)
it handles fine.
in iis, have "request context" provided async
handler, , async
methods default resume in context. whenever await
incomplete task, thread returned thread pool (it not blocked), , when task completes, thread pool thread used continue async
method after entering request context.
so, no threads "held", request is. putting multiple await
s in async
method won't make difference, make difference start multiple task
s , wait them complete, e.g., await task.whenall(task1, task2, task3);
(assuming independent, of course).
i don't know of way verify behavior.
Comments
Post a Comment