示例#1
0
 internal void QueueRequest(RequestEventArgs args)
 {
     System.Diagnostics.Debug.Assert(args != null);
     lock ( m_qRQ )
     {
         if (m_bRQThreadPoolActive)
         {
             m_qRQ.Enqueue(args);
         }
         else
         {
             m_bRQThreadPoolActive = true;
             ThreadPool.QueueUserWorkItem(new WaitCallback(RaiseRequest), args);
         }
     }
 }
示例#2
0
        //m_bStopping, m_strHeadSign, m_straLastNSD, m_strLastSA set only in this method
        private void RaiseRequest(object parm)
        {
            bool             bContinue = true;
            RequestEventArgs args      = (RequestEventArgs)parm;

            do
            {
                bool bRaise = true;
                switch (args.Type)
                {
                case RequestType.DisplayNextStop:
                    switch (args.SubType)
                    {
                    case RequestSubType.None:
                        m_straLastNSD[0] = " ";
                        m_straLastNSD[1] = m_strLastSA = null;
                        args.Value       = m_bStopping ? m_strNSDStopping : m_straLastNSD[0];
                        break;

                    case RequestSubType.ServiceAlert:
                        m_strLastSA = args.Value.ToString();
                        if (m_bStopping)
                        {
                            bRaise = false;
                        }
                        break;

                    default:
                        switch (args.SubType)
                        {
                        case RequestSubType.NextStop:
                            m_straLastNSD[0] = args.Value.ToString();
                            m_straLastNSD[1] = null;
                            m_strLastSA      = null;
                            break;

                        case RequestSubType.NextStopConn:
                            m_straLastNSD = (string[])args.Value;
                            m_strLastSA   = null;
                            break;

                        case RequestSubType.Stopping:
                            m_bStopping = (bool)args.Value;
                            break;
                        }

                        if (m_bStopping)
                        {
                            if (m_straLastNSD[0].Length > 1 || (m_straLastNSD[0].Length > 0 && m_straLastNSD[0][0] != ' '))
                            {
                                args.Value = m_strNSDStopping + m_strNSDStoppingConcat + m_straLastNSD[0];
                            }
                            else
                            {
                                args.Value = m_strNSDStopping;
                            }
                        }
                        else if (m_strLastSA != null)
                        {
                            args.Value = m_strLastSA;
                        }
                        else if (m_straLastNSD[1] != null)
                        {
                            args.Value = m_straLastNSD[0] + m_straLastNSD[1];
                        }
                        else
                        {
                            args.Value = m_straLastNSD[0];
                        }
                        break;
                    }
                    break;

                case RequestType.HeadSign:
                {
                    if (m_strHeadSign != args.Value.ToString())
                    {
                        m_strHeadSign = args.Value.ToString();
                    }
                    else
                    {
                        bRaise = false;
                    }
                    break;
                }
                }

                if (bRaise)
                {
                    EventHandler <RequestEventArgs> handler = Request;
                    if (handler != null)
                    {
                        handler(null, args);
                    }
                }

                lock ( m_qRQ )
                {
                    if (m_qRQ.Count == 0)
                    {
                        args = null;
                    }
                    else
                    {
                        args = m_qRQ.Dequeue();
                    }

                    if (args == null)
                    {
                        bContinue = m_bRQThreadPoolActive = false;
                    }
                }
            }while(bContinue);
        }