Пример #1
0
        private void ArmTimer(Announce announce)
        {
            string path         = announce.Path;
            int    expriationMs = this.GetExpirationMilliSeconds(announce);

            lock (this.deviceMap)
            {
                if (!this.stopped)
                {
                    if (this.deviceMap.ContainsKey(path))
                    {
                        AnnounceTimer timer = this.deviceMap[path];
                        timer.Stop();
                        Announce oldAnnounce = timer.Announce;
                        if (!oldAnnounce.Equals(announce))
                        {
                            timer.Announce = announce;
                            if (this.HandleUpdateDevice != null)
                            {
                                UpdateDeviceEventArgs updateDeviceEvent = new UpdateDeviceEventArgs();
                                updateDeviceEvent.NewAnnounce = announce;
                                updateDeviceEvent.OldAnnounce = oldAnnounce;
                                this.HandleUpdateDevice(this, updateDeviceEvent);
                            }
                        }

                        timer.Interval = expriationMs;
                        timer.Start();
                    }
                    else
                    {
                        AnnounceTimer timer = new AnnounceTimer(expriationMs, announce);
                        timer.AutoReset = false;
                        timer.Elapsed  += new ElapsedEventHandler(this.OnTimedEvent);
                        this.deviceMap.Add(path, timer);
                        timer.Start();
                        if (this.HandleNewDevice != null)
                        {
                            NewDeviceEventArgs newDeviceEvent = new NewDeviceEventArgs();
                            newDeviceEvent.Announce = announce;
                            this.HandleNewDevice(this, newDeviceEvent);
                        }
                    }
                }
            }
        }