I have been looking at how calling BeginReceive on a .NET CF socket can throw an SocketException as per http://msdn.microsoft.com/en-us/library/dxkwh6zw(v=vs.90).aspx?
I looked through the Reflector but I cannot see how this is possible? I think the SocketException is only possible while actually doing the work in a threadpool thread.
My guess is any SocketException is channel through EndReceive().
I have a callback method which calls itself (i.e. BeginReceive(.., .., callback), which contains an EndReceive. I want to make sure that I add a Try-catch in the right place.
Any ideas?
I looked at the .NET Reference Source and it will throw an exception.
Code:
In a method that gets called from overloads of the Begin in a method called DoBeginReceive this method calls this code. The errorcode is passed using the out keyword so it is exactly what is passed back.
EDIT: For .NET CF:
As Stated by the OP
This is the Begin Receive
The addReadRequest does this:
The startWorker does this:
The Thread calls the doWork of the ReceiveAsyncRequestcalls the doRequest of the ReceiveAsyncRequestwhich calls the handleRequest which in turn calls doRequest on the ReceiveAsyncRequest.
The doRequest of the ReceiveAsyncRequest method looks like this:
In the ReceiveFromNoCheck it throws the exception:
If the AsyncResults runs sychronously, it will throw the exception. However, if it is part of the ThreadPool, the exception will just be thrown and kill the application.