mirror of
https://github.com/jayfunc/BetterLyrics.git
synced 2026-01-12 19:08:33 +08:00
- Add album text in lyrics render - Improve song info update and draw algo - Upgrade to .NET 10
32 lines
673 B
C#
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)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|