mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-02 10:45:22 +08:00
32 lines
563 B
C#
32 lines
563 B
C#
using BetterGenshinImpact.Model;
|
|
using System.Threading;
|
|
|
|
namespace BetterGenshinImpact.Core.Script;
|
|
|
|
public class CancellationContext : Singleton<CancellationContext>
|
|
{
|
|
public CancellationTokenSource Cts { get; set; } = new();
|
|
|
|
private bool disposed;
|
|
|
|
public void Set()
|
|
{
|
|
Cts = new CancellationTokenSource();
|
|
disposed = false;
|
|
}
|
|
|
|
public void Cancel()
|
|
{
|
|
if (!disposed)
|
|
{
|
|
Cts.Cancel();
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
Cts.Dispose();
|
|
disposed = true;
|
|
}
|
|
}
|