public void SendMessage(string msg) { if (_handle == null) { CreateHandle(); } int bytesWritten; byte[] bMessage = Encoding.Unicode.GetBytes(msg); bool succeeded = Mailslot.WriteFile(_handle, bMessage, bMessage.Length, out bytesWritten, IntPtr.Zero); if (!succeeded || bMessage.Length != bytesWritten) { if (_handle != null) { _handle.Close(); } _handle = null; throw new Win32Exception(); } }
public void Dispose() { if (_handle != null) { _handle.Close(); _handle = null; } }