Exemplo n.º 1
0
        private void timerCallback(object state)
        {
            ForceValueUpdatedSynchronizationContext.Post(async(chatTrendService) =>
            {
                IChatTrendService service = (IChatTrendService)chatTrendService;
                IForceValueData forceValueData;

                try
                {
                    forceValueData = await service.GetForceValueData();
                }
                catch (ChatTrendServiceException)
                {
                    RemoveService(service);
                    //TODO: サービスが消えたことを伝える
                    return;
                }

                var item = forceValues.FirstOrDefault(x => x.Item1 == chatTrendService);
                if (item != null)
                {
                    forceValues.Remove(item);
                }
                forceValues.Add(new Tuple <IChatTrendService, IForceValueData>(service, forceValueData));

                ForceValueUpdated?.Invoke(this, new ForceValueUpdatedEventArgs(service, forceValueData));
            }, state);
        }
Exemplo n.º 2
0
        public async void AddService(IChatTrendServiceEntry serviceEntry)
        {
            IChatTrendService service = await serviceEntry.GetNewService();

            timers.TryAdd(service, new Timer(timerCallback, service, 1000, (int)service.UpdateInterval.TotalMilliseconds));
            registeredServices.Add(service);
        }
Exemplo n.º 3
0
        public void RemoveService(IChatTrendService service)
        {
            registeredServices.Remove(service);
            Timer timer;

            timers.TryRemove(service, out timer);
            disposeService(service, timer);
        }
Exemplo n.º 4
0
        private void disposeService(IChatTrendService chatTrendService, Timer timer)
        {
            ManualResetEvent waitHandle = new ManualResetEvent(false);

            timer.Dispose(waitHandle);  //Timer破棄
            waitHandle.WaitOne();
            chatTrendService.Dispose(); //ChatTrendService破棄
        }
Exemplo n.º 5
0
 public ForceValueUpdatedEventArgs(IChatTrendService chatTrendService, IForceValueData forceValueData)
 {
     this.ChatTrendService = chatTrendService;
     this.ForceValueData   = forceValueData;
 }