RhSolutions-AddIn/CancellationDisposable.cs
Sergey Chebotar e7d3fe2bea Init commit
2021-11-11 16:33:40 +03:00

39 lines
704 B
C#

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();
}
}
}