Created
June 2, 2014 13:13
-
-
Save renestein/6e08542f90c2152cbb34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Threading; | |
namespace RStein.Async.Schedulers | |
{ | |
public sealed class Work : IDisposable | |
{ | |
private readonly CancellationTokenSource m_cancelTokenSource; | |
public Work(IoServiceScheduler scheduler) | |
{ | |
m_cancelTokenSource = new CancellationTokenSource(); | |
scheduler.AddWork(this); | |
} | |
internal CancellationToken CancelToken | |
{ | |
get | |
{ | |
return m_cancelTokenSource.Token; | |
} | |
} | |
internal void RegisterWorkDisposedHandler(Action action) | |
{ | |
m_cancelTokenSource.Token.Register(action); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
} | |
private void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
m_cancelTokenSource.Cancel(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment