J
Jose Luis Balsera
Hi all,
I'm experiencing a behavior in Socket.Close that I'm not able to explain.
Maybe someone can find a reason for the following:
In my app I use a socket to send and receive data from a server running in a
desktop PC. The app in the server runs under the full .NET Framework. In my
Pocket PC app there's a thread that handles data sending through the socket
and another thread that handles the data receiving. The first thread waits
on an event object to send and the second thread waits on the Socket.Receive
call. Nothing extraordinary until now. The app can communicate with the
server via an ActiveSync connection when the device is in its cradle or via
a GPRS RAS connection when the device is not in the cradle.
When the application ends I awake the sending thread using the event to
terminate it and that works always. But when using the GPRS connection, the
Receive call doesn't terminate with a SocketException if previously a call
to Socket.Shutdown has been made. I've never found a problem calling
Shutdown+Close in the ActiveSync case. I've also observed that if I comment
the call to Shutdown, Receive ends with a SocketException when the socket is
closed.
I thought the correct pattern was Shutdown+Close, but in the GPRS case I can
see the thread hanging for a while after the application ends. Normally, the
exception is thrown in the Receive call after more or less 4 minutes and the
thread is then able to end, so it's the process.
Is this a normal behavior?
What would be the more appropriate way to end the receiving thread?
Thank you very much
I'm experiencing a behavior in Socket.Close that I'm not able to explain.
Maybe someone can find a reason for the following:
In my app I use a socket to send and receive data from a server running in a
desktop PC. The app in the server runs under the full .NET Framework. In my
Pocket PC app there's a thread that handles data sending through the socket
and another thread that handles the data receiving. The first thread waits
on an event object to send and the second thread waits on the Socket.Receive
call. Nothing extraordinary until now. The app can communicate with the
server via an ActiveSync connection when the device is in its cradle or via
a GPRS RAS connection when the device is not in the cradle.
When the application ends I awake the sending thread using the event to
terminate it and that works always. But when using the GPRS connection, the
Receive call doesn't terminate with a SocketException if previously a call
to Socket.Shutdown has been made. I've never found a problem calling
Shutdown+Close in the ActiveSync case. I've also observed that if I comment
the call to Shutdown, Receive ends with a SocketException when the socket is
closed.
I thought the correct pattern was Shutdown+Close, but in the GPRS case I can
see the thread hanging for a while after the application ends. Normally, the
exception is thrown in the Receive call after more or less 4 minutes and the
thread is then able to end, so it's the process.
Is this a normal behavior?
What would be the more appropriate way to end the receiving thread?
Thank you very much