You can do this to check if it is selected. The client is set to null when the UdpClient is deleted.
private void OnUdpData(IAsyncResult result) { if (_udpReceive.Client == null) return; byte[] data = _udpReceive.EndReceive(result, ref _receiveEndPoint);
Although, since you close it in a separate thread, you may encounter a race condition. It is best to just catch an ObjectDisposedException and a SocketException.
private void OnUdpData(IAsyncResult result) { try { byte[] data = _udpReceive.EndReceive(result, ref _receiveEndPoint);
source share