private async Task Tick() { Session currentSession = null; while (!_token.IsCancellationRequested) { await Task.Delay(500 * 1, _token); if (currentSession != null) { try { await UpdateCurrentSession(currentSession); } catch (Exception e) { // after we crash, we come back with the last session, but it hangs. Then MPV comes back up, we update the last session with the new values. BAD!!!! //TODO Here we need to know why we got the exception? Is mpv still running? _logger.LogWarning(e, "Received error when trying to get current position"); currentSession = null; } } if (!_queue.HasItems()) { continue; } var item = _queue.Pop(); await _api.PlayMedia(item.Path, item.StartPosition); await _api.ShowText($"Now playing {item.Path.Substring(item.Path.LastIndexOf('\\') + 1)}", TimeSpan.FromSeconds(5)); var duration = await _api.GetDuration(); currentSession = _sessionFactory.CreateNewSession(item.MediaFileId, duration); } }