var pollingTask = Task.Run(() =>
{
var observer = Observable.Interval(TimeSpan.FromSeconds(1))
.Select(async _ => _CurrentlyPlaying = await _spotifyClient?.Player?.GetCurrentlyPlaying(new()))
.Select(track => CurrentTrackInfo.GetCurrentTrackInfo(_CurrentlyPlaying))
.Distinct()
.Where(track => track is not null)
.Subscribe(track => _CurrentTrackChanged?.Invoke(track));
if (ct.IsCancellationRequested)
{
observer.Dispose();
_CurrentTrackErrorDetected.Invoke();
}
_Logger.WriteLog("[SpotifyService] - Polling Start....", Logger.LogLevel.Debug);
}, ct);
try
{
await pollingTask;
}
catch (Exception ex)
{
if (pollingTask.Exception is AggregateException agex)
{
agex.Handle((exp) =>
{
agex.InnerExceptions.ToList().ForEach((ages) => {
_Logger.WriteLog($"[SpotifyService] - Polling error... {ages.Message}", Logger.LogLevel.Error);
});
// If you set it to true, the exception will not be thrown again because it has already been handled.
// Or else, the exception will be re-throw as it is still unhandled.
return false;
});
}
}
Task.Run() な中で例外処理してしまっているので、取得できていないと思われる https://github.com/Sagiri-Dev/Sagiri/blob/feature-plus-soundcloud/Sagiri/Services/Spotify/SpotifyService.cs#L85-L108
どうするか? 一度 Task として受けた後、try - catch 内で待ち合わせて例外処理する