diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-11-11 16:33:40 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-11-11 16:33:40 +0300 |
commit | e7d3fe2beae326a2380b4cfed7f33961f40d87ca (patch) | |
tree | 8da936709596912823ebbca2790c725fd50d434e /CancellationDisposable.cs |
Init commit
Diffstat (limited to 'CancellationDisposable.cs')
-rw-r--r-- | CancellationDisposable.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/CancellationDisposable.cs b/CancellationDisposable.cs new file mode 100644 index 0000000..700a2c2 --- /dev/null +++ b/CancellationDisposable.cs @@ -0,0 +1,38 @@ +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(); + } + } + +} + + |