Exemplo n.º 1
0
        public static void StartEventMonitor()
        {
            autoEvent            = new AutoResetEvent(false);
            isRunning            = true;
            mainThreadSynContext = SynchronizationContext.Current;
            var thread = new Thread(() =>
            {
                while (isRunning)
                {
                    log.Info("handle the evt");
                    if (queue.Count <= 0)
                    {
                        lock (synObject)
                        {
                            log.Info("No evt, wait..");
                            autoEvent.WaitOne();
                        }
                    }
                    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;
                        }
                        try
                        {
                            callView.Invoke(new Action(() =>
                            {
                                DoEvent(evt);
                            }));
                            //mainThreadSynContext.Post(new SendOrPostCallback(DoEvent), evt);
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                        }
                        WrapperProxy.FreeEvent(evt.EventHandle);
                    }
                }
            });

            thread.Start();
        }