views:

290

answers:

1

To cut a long story short - read this article first and then this article. In short - it's the old issue about ASP.NET and randomly switching among threads. Well, not so randomly actually. As the second article explains, this only happens "when your thread performs an async IO operation". So... what the heck is an async IO operation in this case? I'm familiar with the standard Begin...End...IAsyncResult and the event model for asynchronous IO. But I can't see how this could be tied together with a thread switch.

The point is - I'm simply afraid of any "hidden" asynchronous IO that my software could be doing (and which would then provoke a thread switch). But how to identify them?

A: 

Async IO operations refer to situations where the calling thread does not block in order to wait for IO. Examples include the BeginXXX operations on streams, network connections etc.

When you set up a call using BeginXXX a threadpool thread will be used to execute your callback while a device driver typically handles the actual IO. Thus a number of different threads may be involved.

Brian Rasmussen
True, that I understand. But the page processing will still happen on the same thread (with the exception of the callback). ASP.NET however manages to move the page processing to another thread sometimes.
Vilx-
Well, the quote from Scott Gu says that "sometimes" equals, when your thread does async IO. Async IO still equals IO operations done by the threadpool as far as I understand it.
Brian Rasmussen
Well, actually, some async IO could be done by the kernel itself wihout any threads invloved (as far as I understand it). Like file reading. There is this possibility in plain Win32 too (and it's recommended as the fastest IO option).
Vilx-
What I don't understand is that, OK, I have this IO task that I would like to do in an async way. So in, say Page_Load I call the BeginOperation() method. The async operation starts, but the method returns immediately and continues the page lifecycle.
Vilx-
Then follow the event handlers, Page_PreRender, etc. While the IO operation happens...somewhere else. Then, at some point (like Page_Render) I check the IAsyncResult status. It's completed, so I call EndOperation() and am done with it. So... at which point could the thread-switch happen? And why?
Vilx-