Ejemplo n.º 1
0
        protected Context(string name)
        {
            Name         = name;
            currentState = eventPump.IsRunning;
            Keyboard     = Keyboard.Instance;

            eventPump.EventPumpStateChanged += OnEventPumpStateChanged;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Start the pump
 /// </summary>
 public void Start()
 {
     if (pumpState == EventPumpState.Stopped)                // Ignore if already started
     {
         this.pumpThread      = new Thread(new ThreadStart(PumpThreadProc));
         this.pumpThread.Name = "EventPumpThread";
         pumpState            = EventPumpState.Pumping;
         this.pumpThread.Start();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Start the pump
 /// </summary>
 public void Start()
 {
     if (this.PumpState == EventPumpState.Stopped)                // Ignore if already started
     {
         this.pumpThread          = new Thread(new ThreadStart(PumpThreadProc));
         this.pumpThread.Name     = "EventPumpThread" + this.Name;
         this.pumpThread.Priority = ThreadPriority.Highest;
         pumpState = EventPumpState.Pumping;
         this.pumpThread.Start();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Tell the pump to stop after emptying the queue.
 /// </summary>
 public void Stop()
 {
     if (pumpState == EventPumpState.Pumping)               // Ignore extra calls
     {
         lock ( events )
         {
             pumpState = EventPumpState.Stopping;
             Monitor.Pulse(events);                       // In case thread is waiting
         }
         this.pumpThread.Join();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Our thread proc for removing items from the event
        /// queue and sending them on. Note that this would
        /// need to do more locking if any other thread were
        /// removing events from the queue.
        /// </summary>
        private void PumpThreadProc()
        {
            EventListener hostListeners = CoreExtensions.Host.Listeners;

            Monitor.Enter(events);
            try
            {
                while (this.events.Count > 0 || pumpState == EventPumpState.Pumping)
                {
                    while (this.events.Count > 0)
                    {
                        Event e = this.events.Dequeue();
                        e.Send(this.eventListener);
                        e.Send(hostListeners);
                        if (autostop && e is RunFinishedEvent)
                        {
                            pumpState = EventPumpState.Stopping;
                        }
                    }
                    // Will be pulsed if there are any events added
                    // or if it's time to stop the pump.
                    if (pumpState != EventPumpState.Stopping)
                    {
                        Monitor.Wait(events);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Exception in pump thread", ex);
            }
            finally
            {
                Monitor.Exit(events);
                pumpState = EventPumpState.Stopped;
                //pumpThread = null;
            }
        }
Ejemplo n.º 6
0
        private void OnEventPumpStateChanged(DispatchState state)
        {
            if (currentState == state)
            {
                return;
            }

            // state change is occuring
            switch (state)
            {
            case DispatchState.Running:
                currentState = state;
                StartContext();

                break;

            case DispatchState.Idle:
                currentState = state;
                StopContext();

                break;
            }
        }
Ejemplo n.º 7
0
		/// <summary>
		/// Start the pump
		/// </summary>
		public void Start()
		{
			if ( pumpState == EventPumpState.Stopped )  // Ignore if already started
			{
				this.pumpThread = new Thread( new ThreadStart( PumpThreadProc ) );
				this.pumpThread.Name = "EventPumpThread";
                pumpState = EventPumpState.Pumping;
                this.pumpThread.Start();
			}
		}
Ejemplo n.º 8
0
		/// <summary>
		/// Our thread proc for removing items from the event
		/// queue and sending them on. Note that this would
		/// need to do more locking if any other thread were
		/// removing events from the queue.
		/// </summary>
		private void PumpThreadProc()
		{
			EventListener hostListeners = CoreExtensions.Host.Listeners;
			Monitor.Enter( events );
            try
            {
                while (this.events.Count > 0 || pumpState == EventPumpState.Pumping)
                {
                    while (this.events.Count > 0)
                    {
                        Event e = this.events.Dequeue();
                        e.Send(this.eventListener);
						e.Send(hostListeners);
                        if (autostop && e is RunFinishedEvent)
                            pumpState = EventPumpState.Stopping;
                    }
                    // Will be pulsed if there are any events added
                    // or if it's time to stop the pump.
                    if ( pumpState != EventPumpState.Stopping )
                        Monitor.Wait(events);
                }
            }
            catch (Exception ex)
            {
                log.Error( "Exception in pump thread", ex );
            }
			finally
			{
				Monitor.Exit( events );
                pumpState = EventPumpState.Stopped;
				//pumpThread = null;
			}
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Tell the pump to stop after emptying the queue.
		/// </summary>
		public void Stop()
		{
			if ( pumpState == EventPumpState.Pumping ) // Ignore extra calls
			{
				lock( events )
				{
					pumpState = EventPumpState.Stopping;
					Monitor.Pulse( events ); // In case thread is waiting
				}
				this.pumpThread.Join();
			}
		}
Ejemplo n.º 10
0
 /// <summary>
 /// Start the pump
 /// </summary>
 public void Start()
 {
     if ( this.PumpState == EventPumpState.Stopped )  // Ignore if already started
     {
         this.pumpThread = new Thread( new ThreadStart( PumpThreadProc ) );
         this.pumpThread.Name = "EventPumpThread" + this.Name;
         this.pumpThread.Priority = ThreadPriority.Highest;
         pumpState = EventPumpState.Pumping;
         this.pumpThread.Start();
     }
 }