Exemplo n.º 1
0
        public int addTask(CEventInfo cTaskInof)
        {
            CEventInfo _cTaskInof = new CEventInfo(4294967295);///初始化UInt32最大值

            _cTaskInof = cTaskInof;
            listEventData.Add(_cTaskInof);
            return(listEventData.Count - 1);
        }
Exemplo n.º 2
0
        private void procEventLoop()
        {
            while (m_stop == false)
            {
                SpinWait.SpinUntil(() => listEventData.Count > 0 || m_stop == true, -1);
                if (m_stop == true)
                {
                    break;
                }
                if (listEventData.Count > 0)
                {
                    //取得第一筆資料
                    CEventInfo _cTaskInof = new CEventInfo(4294967295);///初始化UInt32最大值
                    Monitor.Enter(listEventData);
                    _cTaskInof = listEventData[0];
                    listEventData.RemoveAt(0);
                    if (_cTaskInof == null)
                    {
                        continue;
                    }

                    Monitor.Enter(listEventData);

                    InvokeDelegate fnProcThis;
                    try
                    {
                        if (listProcFuncitons.TryGetValue(_cTaskInof.nEventCode, out fnProcThis))
                        {
                            Thread thProcEvent = new Thread(() => fnProcThis(_cTaskInof));
                            thProcEvent.SetApartmentState(ApartmentState.STA); //Set the thread to STA
                            thProcEvent.Start();
                        }
                        else
                        {
                            CDebug.jmsg("[錯誤]處理事件:{0}未設定處理函式\n", _cTaskInof.nEventCode);
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        CDebug.jmsgEx("[EventPorc]Exception!!{0}", e.Message);
                        continue;
                    }
                }
            }
        }