Files
BetterLyrics/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Helper/LatestOnlyTaskRunner.cs
Zhe Fang 4926fe55a3 chores:
- Add album text in lyrics render
- Improve song info update and draw algo
- Upgrade to .NET 10
2025-11-12 19:15:19 -05:00

32 lines
673 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Helper
{
public class LatestOnlyTaskRunner
{
private CancellationTokenSource? _cts;
public async Task RunAsync(Func<CancellationToken, Task> taskFactory)
{
_cts?.Cancel();
_cts?.Dispose();
_cts = new CancellationTokenSource();
var token = _cts.Token;
try
{
await taskFactory(token);
}
catch (OperationCanceledException)
{
}
catch (Exception)
{
}
}
}
}