private static void DisconnectCallback(IAsyncResult IAR) { StateObject state = (StateObject)IAR.AsyncState; Socket handler = state.workSocket; string key = state.key; handler.EndDisconnect(IAR); handler.Shutdown(SocketShutdown.Both); handler.Disconnect(true); handler.Close(); handler.Dispose(); D2Sockets.Remove(key); D2TReceive.Remove(key); D2TSend.Remove(key); D3BReceive.Remove(key); D3BSend.Remove(key); }
public void Stop(string key) { StateObject state = D2Sockets.Get(key); try { if (state != null && state.workSocket != null) { Socket handler = state.workSocket; handler.Shutdown(SocketShutdown.Both); handler.Disconnect(true); handler.Close(); handler.Dispose(); } } catch { } finally { if (D2Sockets != null) { D2Sockets.Remove(key); } if (D2TReceive != null) { D2TReceive.Remove(key); } if (D2TSend != null) { D2TSend.Remove(key); } if (D3BReceive != null) { D3BReceive.Remove(key); } if (D3BSend != null) { D3BSend.Remove(key); } } }