예제 #1
0
        internal void EnsureLockQueuesOpen()
        {
            int attempts = 0;

            // handle lock queue name collisions, if we fail three times in a row it is probably not the name
            // collision that is causing the open to fail
            while (true)
            {
                try
                {
                    this.lockQueueForReceive.EnsureOpen();
                    break;
                }
                catch (MsmqException ex)
                {
                    if (attempts >= 3)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex);
                    }
                    MsmqDiagnostics.ExpectedException(ex);
                }

                this.lockQueueForReceive.Dispose();
                this.lockQueueForMove.Dispose();

                this.lockQueueName       = this.formatName + ";" + MsmqSubqueueLockingQueue.GenerateLockQueueName();
                this.lockQueueForReceive = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_RECEIVE_ACCESS, UnsafeNativeMethods.MQ_DENY_RECEIVE_SHARE);
                this.lockQueueForMove    = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_MOVE_ACCESS);
                attempts++;
            }
            this.lockQueueForMove.EnsureOpen();
        }
예제 #2
0
        public MsmqSubqueueLockingQueue(string formatName, string hostname, int accessMode)
            : base(formatName, accessMode)
        {
            // The hostname will be empty for MsmqIntegrationBinding
            if (string.Compare(hostname, string.Empty, StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.validHostName = MsmqSubqueueLockingQueue.TryGetHostName(formatName, out hostname);
            }
            else
            {
                this.validHostName = true;
            }

            this.disposed            = false;
            this.lockQueueName       = this.formatName + ";" + MsmqSubqueueLockingQueue.GenerateLockQueueName();
            this.lockQueueForReceive = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_RECEIVE_ACCESS, UnsafeNativeMethods.MQ_DENY_RECEIVE_SHARE);
            this.lockQueueForMove    = new MsmqQueue(this.lockQueueName, UnsafeNativeMethods.MQ_MOVE_ACCESS);
            this.mainQueueForMove    = new MsmqQueue(this.formatName, UnsafeNativeMethods.MQ_MOVE_ACCESS);
            this.lockCollectionTimer = new IOThreadTimer(new Action <object>(OnCollectionTimer), null, false);

            if (string.Compare(hostname, "localhost", StringComparison.OrdinalIgnoreCase) == 0)
            {
                this.hostname = null;
            }
            else
            {
                this.hostname = hostname;
            }
        }