示例#1
0
 public void Dispose()
 {
     if (_handle != null)
     {
         _handle.Close();
         _handle = null;
     }
 }
示例#2
0
        private void CreateHandle()
        {
            _handle = Mailslot.CreateFile(
                @"\\" + _machine + @"\mailslot\" + _name,
                Mailslot.FileDesiredAccess.GenericWrite,
                Mailslot.FileShareMode.FileShareRead,
                IntPtr.Zero,
                Mailslot.FileCreationDisposition.OpenExisting,
                0,
                IntPtr.Zero);

            if (_handle.IsInvalid) throw new Win32Exception();
        }
示例#3
0
 public MailslotServer(string name)
 {
     _handle = Mailslot.CreateMailslot(@"\\.\mailslot\" + name, 0, 0, IntPtr.Zero);
     if (_handle.IsInvalid) throw new Win32Exception();
 }
示例#4
0
        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();
            }
        }