private void FireOnDisconnect(DisconnectedEventArgs d) { if (Interlocked.CompareExchange(ref _disconnectEventFired, TRUE, FALSE) == FALSE) { if (d.DisconnectReason != null) { SocketException se = d.DisconnectReason as SocketException; string msg = (se != null) ? ((SocketError)se.ErrorCode).ToString() : d.DisconnectReason.Message; Log("EVENT Disconnected: " + msg); } else { Log("EVENT Disconnected: " + (d.DisconnectReason != null ? d.DisconnectReason.Message : "")); } if (OnDisconnect != null) { if (_synchContext == null) { OnDisconnect(this, d); } else { _synchContext.BeginInvoke(new EventHandler<DisconnectedEventArgs>(OnDisconnect), this, d); } } } else { Log("EVENT Disconnected NOT FIRED!"); } }
private void FireOnDisconnect(DisconnectedEventArgs d) { Log("EVENT Disconnected:"); if (OnDisconnect != null) { if (_synchContext == null) { OnDisconnect(this, d); } else { _synchContext.BeginInvoke(new EventHandler<DisconnectedEventArgs>(OnDisconnect), this, d); } } }