Exemple #1
0
        private async void StartPollingTimers()
        {
            log.Trace("StartPollingTimers(): Start.");

            var c1 = new CancellationTokenSource();
            var c2 = new CancellationTokenSource();
            var c3 = new CancellationTokenSource();
            var c4 = new CancellationTokenSource();


            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () => PlayerListCommand.RefreshPlayerList(),
                        cancelToken: c1.Token,
                        intervalInMilliseconds:
                        this.Config.PollIntervalMs_PlayerListCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () =>
                        ServerInfoCommand.RefreshServerInfo(),
                        cancelToken: c2.Token,
                        intervalInMilliseconds: this.Config.PollIntervalMs_ServerInfoCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            Task.Run(async() =>
            {
                try
                {
                    await PeriodicTaskFactory.Start(
                        () =>
                        ClientChatBufferCommand.RefreshClientChatBufferCommand(),
                        cancelToken: c3.Token,
                        intervalInMilliseconds: this.Config.PollIntervalMs_ClientChatBufferCommand,
                        delayInMilliseconds: 1000,
                        synchronous: true);
                }
                catch (OperationCanceledException operationCanceledException) { }
                catch (Exception exception) { }
            });
            //Task.Run(async () =>
            //{
            //    try
            //    {
            //        await PeriodicTaskFactory.Start(() => GetAdminListCommand.RefreshAdminList(), cancelToken: c4.Token, intervalInMilliseconds: this.Config.PollIntervalMs_AdminListCommand, delayInMilliseconds: 1000, synchronous: true);
            //    }
            //    catch (OperationCanceledException operationCanceledException) { }
            //});



            _pollingTimerCancelAction = new Action(() =>
            {
                c1.Cancel();
                c2.Cancel();
                c3.Cancel();
                c4.Cancel();
            });

            //while (true)
            //{
            //    PlayerListCommand.RefreshPlayerList();
            //    ServerInfoCommand.RefreshServerInfo();
            //    ClientChatBufferCommand.RefreshClientChatBufferCommand();
            //    //GetAdminListCommand.RefreshAdminList();

            //    await Task.Delay(StatusPullDelayMs);
            //    if (!_connected)
            //        break;
            //}
            log.Trace("StartPollingTimers(): End");
        }