How to catch exceptions from another thread without affecting the debugger

I have a udp service listening on a socket for the udp datagrams:

int result = 0;
try
{
  result = m_ReceivingSocket.Receive(buffer);
}
catch (SocketException e)
{
  Log.Debug("Timed out with socket exception, so no result was found.", e);
}

      

It does this on a timer every 1 millisecond because it's important that I get the udp message as soon as possible. Most of the time, a socket exception is thrown because the socket will time out. This is because the socket is set to timeout:

receivingSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000);

      

Unfortunately, when I run this, the Visual Studio debugger won't let me execute the code. He thinks another thread is still running and won't let me continue. Has anyone seen this before? Does anyone know a better way to get from a socket without handling exceptions?

0


a source to share


1 answer


Have you tried setting a debug condition that causes the timeout to change to infinity?



#if (DEBUG)
receivingSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 0);
#endif

      

0


a source







All Articles