コード例 #1
0
ファイル: QActive.cs プロジェクト: djpnewton/ddraw
        /// <summary>
        /// This method is executed on the dedicated thread of this <see cref="QActive"/> instance.
        /// </summary>
        private void DoEventLoop()
        {
            this.Init();
            // Once initialized we kick off our event loop
            try
            {
                while(true)
                {
                    IQEvent qEvent = m_EventQueue.DeQueue(); // this blocks if there are no events in the queue
                    //Debug.WriteLine(String.Format("Dispatching {0} on thread {1}.", qEvent.ToString(), Thread.CurrentThread.Name));
                    this.Dispatch(qEvent);
                    // QF.Propagate(qEvent);
                }
            }
            catch(ThreadAbortException)
            {
                // We use the method Thread.Abort() in this.Abort() to exit from the event loop
                Thread.ResetAbort();
            }

            // The QActive object ends
            m_ExecutionThread = null;
            OnExecutionAborted();
        }
コード例 #2
0
ファイル: QActive.cs プロジェクト: djpnewton/ddraw
        public void Start(int priority)
        {
            if (m_ExecutionThread != null)
            {
                throw new InvalidOperationException("This active object is already started. The Start method can only be invoked once.");
            }

            // Note: We use the datatype int for the priority since uint is not CLS compliant
            if (priority < 0)
            {
                throw new ArgumentException("The priority of an Active Object cannot be negative.", "priority");
            }
            m_Priority = priority;
            // TODO: Leverage the priority
            m_ExecutionThread = Threading.ThreadFactory.GetThread(0, new ThreadStart(this.DoEventLoop));
            m_ExecutionThread.Start();
        }