コード例 #1
0
        public override Task StopAsync(CancellationToken cancellationToken)
        {
            _th_ManageNewMessages_CancTokenSource.Cancel(); //request cancellation of threads

            //for each thread, register a fake message to unlock and stop it
            _th_ManageNewMessages_list.ForEach(_ => MainHubData.RegisterMessage(new ChatMessage(null, null)));
            return(base.StopAsync(cancellationToken));
        }
コード例 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);

                _logger.LogInformation("Clients currently active on the server: " + String.Join(", ", MainHubData.GetUsers().Values.ToList()));
                await _mainHub.Clients.All.ShowMessage(ChatMessage.CreateAsJSON(MainHubData.ServerUser, "Server is working.",
                                                                                ChatMessage.MessageType.Info));

                await Task.Delay(30000, stoppingToken);
            }
        }