RhSolutions-AddIn/CancellationDisposable.cs

39 lines
704 B
C#
Raw Normal View History

2021-11-11 16:33:40 +03:00
using System;
using System.Threading;
namespace Rehau.Sku.Assist
{
sealed class CancellationDisposable : IDisposable
{
readonly CancellationTokenSource cts;
public CancellationDisposable(CancellationTokenSource cts)
{
if (cts == null)
{
throw new ArgumentNullException("cts");
}
this.cts = cts;
}
public CancellationDisposable()
: this(new CancellationTokenSource())
{
}
public CancellationToken Token
{
get { return cts.Token; }
}
public void Dispose()
{
cts.Cancel();
}
}
}