示例#1
0
        public void start()
        {
            autoEvent = new AutoResetEvent(false);
            isRunning = true;
            var thread = new Thread(() =>
            {
                while (isRunning)
                {
                    log.Info("handle the evt");
                    if (queue.Count() == 0)
                    {
                        lock (synObject)
                        {
                            log.Info("No evt, wait..");
                            //queue.wait();
                            autoEvent.WaitOne();
                        }
                    }
                    log.Info("EventQ getEvent: total = " + queue.Count());
                    while (queue.Count() > 0)
                    {
                        Event evt = null;
                        lock (synObject)
                        {
                            evt = queue.Dequeue();
                        }
                        // dispatch Event to proper modules
                        if (evt == null)
                        {
                            log.Error("Event is null!");
                            continue;
                        }
                        if (null != Dispatcher)
                        {
                            try
                            {
                                Dispatcher.Invoke(new Action(() =>
                                {
                                    DoEvent(evt);
                                }));
                            }catch (Exception ex)
                            {
                                log.Error(ex.Message);
                            }
                        }
                        WrapperProxy.FreeEvent(evt.EventHandle);
                    }
                }
            });

            thread.Start();
        }