// The demand is not added now (in 4.5), to avoid a breaking change. To be considered in the next version.

        /*
         * // We demand full trust because this method calls into MessageQueue, which is defined in a non-APTCA assembly.
         * // MSMQ is not enabled in partial trust, so this demand should not break customers.
         * [PermissionSet(SecurityAction.Demand, Unrestricted = true)]
         */
        void OnTimer(object state)
        {
            try
            {
                if (this.currentState != CommunicationState.Opened)
                {
                    return;
                }

                lock (this.thisLock)
                {
                    if (this.retryMatchedFilters)
                    {
                        RetryMatchFilters(knownPublicQueues.Values);
                        RetryMatchFilters(knownPrivateQueues.Values);
                    }

                    bool scanNeeded = ((this.retryMatchedFilters == false) ||
                                       (this.retryMatchedFilters && (this.iteration % 2) != 0));
                    if (scanNeeded)
                    {
                        MsmqDiagnostics.ScanStarted();

                        // enumerate the public queues first
                        try
                        {
                            MessageQueue[] queues = MessageQueue.GetPublicQueuesByMachine(this.host);
                            ProcessFoundQueues(queues, knownPublicQueues, false);
                        }
                        catch (MessageQueueException ex)
                        {
                            MsmqDiagnostics.CannotReadQueues(this.host, true, ex);
                        }

                        // enumerate the private queues next
                        try
                        {
                            MessageQueue[] queues = MessageQueue.GetPrivateQueuesByMachine(this.host);
                            ProcessFoundQueues(queues, knownPrivateQueues, true);
                        }
                        catch (MessageQueueException ex)
                        {
                            MsmqDiagnostics.CannotReadQueues(this.host, false, ex);
                        }

                        // Figure out if we lost any queues:
                        ProcessLostQueues(knownPublicQueues);
                        ProcessLostQueues(knownPrivateQueues);
                    }

                    this.iteration++;
                    this.timer.Set(this.updateInterval);
                }
            }
            finally
            {
                this.firstRoundComplete.Set();
            }
        }
 private void OnTimer(object state)
 {
     try
     {
         lock (this.thisLock)
         {
             if (this.currentState == CommunicationState.Opened)
             {
                 MsmqDiagnostics.ScanStarted();
                 try
                 {
                     MessageQueue[] publicQueuesByMachine = MessageQueue.GetPublicQueuesByMachine(this.host);
                     this.ProcessFoundQueues(publicQueuesByMachine, this.knownPublicQueues, false);
                 }
                 catch (MessageQueueException exception)
                 {
                     MsmqDiagnostics.CannotReadQueues(this.host, true, exception);
                 }
                 try
                 {
                     MessageQueue[] privateQueuesByMachine = MessageQueue.GetPrivateQueuesByMachine(this.host);
                     this.ProcessFoundQueues(privateQueuesByMachine, this.knownPrivateQueues, true);
                 }
                 catch (MessageQueueException exception2)
                 {
                     MsmqDiagnostics.CannotReadQueues(this.host, false, exception2);
                 }
                 this.ProcessLostQueues(this.knownPublicQueues);
                 this.ProcessLostQueues(this.knownPrivateQueues);
                 this.iteration++;
                 this.timer.Set(this.updateInterval);
             }
         }
     }
     finally
     {
         this.firstRoundComplete.Set();
     }
 }