Exemple #1
0
 public void Dispose()
 {
     if (_handle != null)
     {
         _handle.Close();
         _handle = null;
     }
 }
Exemple #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();
    }
Exemple #3
0
 public MailslotServer(string name)
 {
     _handle = Mailslot.CreateMailslot(@"\\.\mailslot\" + name, 0, 0, IntPtr.Zero);
     if (_handle.IsInvalid) throw new Win32Exception();
 }
Exemple #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();
        }
    }