Ejemplo n.º 1
0
        /// <summary>
        /// Create a mailslot.
        /// </summary>
        /// <param name="name">Name of the mailslot.</param>
        /// <param name="maxMessageSize">Maximum size, in bytes, of messages that can be posted to the mailslot. 0 means any size.</param>
        /// <param name="readTimeout">
        /// Timeout, in milliseconds, that a read operation will wait for a message to be posted. 0 means do not wait, uint.MaxValue means
        /// wait indefinitely.
        /// </param>
        public static SafeMailslotHandle CreateMailslot(string name, uint maxMessageSize = 0, uint readTimeout = 0)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            SafeMailslotHandle handle;

            unsafe
            {
                handle = Direct.CreateMailslotW(name, maxMessageSize, readTimeout, null);
            }

            if (handle.IsInvalid)
            {
                throw ErrorHelper.GetIoExceptionForLastError(name);
            }

            return(handle);
        }