public async Task Start(ParseMessage parseMessage) { _source = new CancellationTokenSource(); PeriodicTaskAction <object, CancellationToken> keepChannel = (async(object o, CancellationToken t) => { if (_webSocketClient == null) { _webSocketClient = new ClientWebSocket(); _webSocketClient.Options.KeepAliveInterval = new TimeSpan(keepAliveSocketInterval * TimeSpan.TicksPerSecond); await SocketConnect(parseMessage); } else if (_webSocketClient.State != WebSocketState.Open && _webSocketClient.State != WebSocketState.Connecting) { _webSocketClient.Dispose(); _webSocketClient = new ClientWebSocket(); _webSocketClient.Options.KeepAliveInterval = new TimeSpan(keepAliveSocketInterval * TimeSpan.TicksPerSecond); await SocketConnect(parseMessage); } } ); tickerchnl = new PeriodicTaskWrapper(_logger, _name); await tickerchnl.Start(keepChannel, new PeriodicTaskParams { period = (int)keepAliveSecs * 1000 }, _source.Token); }
public override void OnStart() { base.OnStart(); webApp = WebApp.Start <Startup>("http://localhost:8090"); periodicTask.Start(TimeSpan.FromSeconds(5), (_) => { var serverTime = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); var usersCount = ChatHub.Connections.Count; ChatHub.HubClients.All.setStatus($"Server time: {serverTime}, current users: {usersCount}"); LogInfo("ping sent!"); }); }
public void Start() { _cancellationTokenSource = _cancellationTokenSourceFactory.Create(); _periodicTask.Start(_configuration.CacheTrimInterval, _cancellationTokenSource.Token); }
public void On_start_starts_created_periodic_task_with_correct_arguments() { _periodicCacheCleaner.Start(); A.CallTo(() => _fakePeriodicTask.Start(_validConfiguration.CacheTrimInterval, A <CancellationToken> ._)).MustHaveHappened(); }