示例#1
0
        private void ReadEventInternal(IPSEventQueue queue)
        {
            List <PSEvent> eventList = null;

            if (Wait.IsPresent)
            {
                if (queue.HasEvents == false)
                {
                    // need to launch new thread here -- blocking the pipeline thread with a wait
                    // deadlocks something, but joining does not - not sure what's going on here, yet.
                    var t = new Thread(WaitForEventOrBreak);
                    t.IsBackground = true;
                    t.Start(queue);
                    while (t.IsAlive)
                    {
                        // process messages
                        Application.DoEvents();
                        Thread.Sleep(100);
                    }
                    t.Join();
                }
            }
            eventList = queue.DequeueAll(this.NoFlush);

            if (eventList != null)
            {
                WriteObject(eventList, true);
            }
        }
示例#2
0
        /// <summary>
        /// Worker thread for listening to spool
        /// </summary>
        private static void WaitForEventOrBreak(object state)
        {
            IPSEventQueue queue  = (IPSEventQueue)state;
            PSQueueHelper helper = PSQueueHelper.Instance;

            while (queue.HasEvents == false && (!helper.CtrlCHit))
            {
                // com/sendmessage pumping
                Thread.CurrentThread.Join(100);
            }
        }
示例#3
0
        protected override void EndProcessing()
        {
            Dump("Begin");
            IPSEventQueue queue = GetQueue();

            try
            {
                ReadEventInternal(queue);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString(), "GetEvent Error");
                var error = new ErrorRecord(ex, "EventReadFailed", ErrorCategory.ReadError, null);
                ThrowTerminatingError(error);
            }
            Dump("End");
        }
示例#4
0
        protected override void EndProcessing()
        {
            IEnumerable queueNames = (this.QueueName ?? (IEnumerable)PSQueueHelper.Instance.QueueNames);

            foreach (string queueName in queueNames)
            {
                IPSEventQueue queue = PSQueueHelper.Instance.GetEventQueue(queueName);

                if (queue.Count > 0 || ShowEmpty.IsPresent)
                {
                    PSObject obj = new PSObject();
                    obj.Properties.Add(new PSNoteProperty("QueueName", queueName));
                    obj.Properties.Add(new PSNoteProperty("Count", queue.Count));
                    //obj.Properties.Add(new PSNoteProperty("Last", queueName));
                    WriteObject(obj);
                }
                else
                {
                    WriteVerbose("Skipping empty queue: " + queueName);
                }
            }
        }
示例#5
0
 protected override void BeginProcessing()
 {
     m_queue = (this.QueueName == null) ?
               PSQueueHelper.Instance.DefaultQueue
       : PSQueueHelper.Instance.GetEventQueue(this.QueueName);
 }