예제 #1
0
        /// <summary>
        /// Creates a named queue.
        /// </summary>
        /// <param name="forReading">true for a read only queue; false for writing queue</param>
        /// <param name="name">Name of queue</param>
        /// <param name="maxMessageLength">Maximum length of a message in bytes.</param>
        /// <param name="maxMessages">Maximum number of messages allowed in queue, if it is zero, then no restriction on the number of messages.</param>
        public P2PMessageQueue(bool forReading, string name, int maxMessageLength, int maxMessages)
        {
            if (name != null && name.Length > NativeMethods.MAX_PATH)
            {
                throw new ArgumentException("name too long");
            }

            if (maxMessageLength <= 0)
            {
                throw new ArgumentException("maxMessageLength must be positive");
            }

            if (maxMessages < 0)
            {
                throw new ArgumentException("maxMessages must be positive or zero (unbounded)");
            }

            // setup options for creation
            MsgQueueOptions opt = new MsgQueueOptions(forReading, maxMessageLength, maxMessages);

            // configure queue behaviour
            opt.dwFlags = GetBehaviourFlag();

            try
            {
                hQue = NativeMethods.CreateMsgQueue(name, opt);
            }
            catch (MissingMethodException)
            {
                throw new PlatformNotSupportedException();
            }

            if (hQue.Equals(InvalidHandle))
            {
                throw new ApplicationException("Could not create queue " + name + ", NativeError: " + Marshal.GetLastWin32Error());
            }

            mIsForReading = forReading;
            mName         = name;

            if (forReading)
            {
                this.mReadBuffer = new byte[maxMessageLength];
                this.StartEventThread();
            }
        }
예제 #2
0
 public static extern IntPtr OpenMsgQueue(IntPtr hSrcProc, IntPtr hMsgQ, Messaging.MsgQueueOptions lpOptions);
예제 #3
0
 public static extern IntPtr CreateMsgQueue(string lpszName, Messaging.MsgQueueOptions lpOptions);