public void SendHeartBeatFrom(string playerId) { new Thread(async() => { Thread.CurrentThread.IsBackground = true; Thread.Sleep(DefaultHeartbeatPeriodInSeconds * 1000); var heartBeatRequest = new HeartBeatRequest(playerId); await _paintBotClient.SendAsync(heartBeatRequest, CancellationToken.None); }).Start(); }
public void SendHeartBeatFrom(string playerId, CancellationToken ct) { new Thread(async() => { Thread.CurrentThread.IsBackground = true; try { await Task.Delay(DefaultHeartbeatPeriodInSeconds * 1000, ct); } catch (TaskCanceledException) { } if (!ct.IsCancellationRequested && _paintBotClient.IsOpen) { var heartBeatRequest = new HeartBeatRequest(playerId); await _paintBotClient.SendAsync(heartBeatRequest, CancellationToken.None); } }).Start(); }