示例#1
0
        private void BroadcastingThreadMethod()
        {
            try
            {
                using (_observer = new InputDeltaObserver())
                {
                    using (StartCommunicator())
                    {
                        _observer.StartCapturing();
                        LogExceptions(_observer.ProcessingExceptions);
                        _communicator.Start();

                        OnDriversReady();

                        while (_isRunning)
                        {
                            lock (this)
                            {
                                _observer.UpdateTick();
                                LogExceptions(_observer.ProcessingExceptions);

                                if (_observer.DirtiedDeltas.Count > 0)
                                {
                                    //Filter dirtied deltas
                                    //TODO

                                    //Serialize and send
                                    var dirtied = _observer.SerializeDirtied();
                                    _communicator.Broadcast(dirtied);
                                }
                            }

                            Thread.Sleep(_updateTick);
                        }

                        _communicator.Stop();
                        _communicator.Dispose();
                        _communicator = null;
                    }
                    _observer.StopCapturing();
                    _observer.Dispose();
                    LogExceptions(_observer.ProcessingExceptions);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }
        }