0

Just looking for confirmation or documentation regarding how threads are used for the async patterns on sockets under Windows CE, specifically for a socket's BeginRead. I've looked on MSDN's documentation, but I can only find vague references. I've searched here for it and have found answers to the desktop threading model. As a side note, the program is implemented in Compact Framework.

My understanding is thus: On the desktop calling BeginXXX, the callback may or may not be invoked by a different thread than the thread calling BeginXXX. (Taken from the ThreadPool from what I've read and experimented with)

On Windows CE, when calling BeginXXX, the callback is handled by the thread that made the call to BeginXXX.

Is this accurate? If so, where can I find the documentation on it? STW didn't help, and neither did RTM.

  • 1
    This is not documented for a good reason, you *must* assume that the callback can be made on an I/O completion thread. No shortcuts allowed, ignoring it will get you in trouble. It is certainly possible to get the callback on the same thread, that happens when the enough data happens to be buffered. Somewhat likelier to happen on a device with a slow cpu perhaps. – Hans Passant Mar 14 '12 at 16:57
  • @HansPassant 'assume that the callback can be made on an I/O completion thread - yes. I can't see how the originating thread might be signaled to execute a callback unless the IO proceeds in a synchronous manner or needs to make 'alertable' calls. The originating thread may be busy at callback-time or possibly not even exist. – Martin James Mar 14 '12 at 17:46
  • I can't imagine that there would be a good reason not to document it. My app receives messages on a socket with BeginReceive. I send commands with Send(). Sent commands result in an 'OK' being received async. Some OK's I must wait for. I use ManualResetEvent to WaitOne() for an OK after those commands. This ALWAYS times out and during that timeout I receive nothing on that socket. After the reset event fails, I get the OK. The only way I can explain it is if the calling thread is the one expected to handle the callback from BeginReceive. – Scott Pavetti Mar 14 '12 at 20:26

1 Answers1

0

I had to do the threading manually. The threading model is slightly different on Windows CE 6 than it is on desktop platforms. The asynchronous code worked fine when I developed it on the desktop but wouldn't work at all on CE. I ended up shimming in send and receive threads that sat on top of the sockets. I'm still not sure of the reason, I'm going to guess that the vendors that wrote the platform code for the hardware drivers made some decisions that weren't quite on par with what the compact framework is expecting. Anyway, it works now, and the threads that are blocking are mine, and can block without stopping the main thread.