Created
July 11, 2015 16:48
-
-
Save RolandPheasant/b039b167605a457d9e07 to your computer and use it in GitHub Desktop.
Customer dispatcher scheduler
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
public class MyDispatcherScheduler: IScheduler | |
{ | |
private readonly DispatcherScheduler _dispatcherScheduler; | |
private readonly ImmediateScheduler _immediateScheduler = ImmediateScheduler.Instance; | |
public MyDispatcherScheduler(DispatcherScheduler original) | |
{ | |
_dispatcherScheduler = original; | |
} | |
public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action) | |
{ | |
return GetScheduler().Schedule(state, action); | |
} | |
public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action) | |
{ | |
return GetScheduler().Schedule(state,dueTime, action); | |
} | |
public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action) | |
{ | |
return GetScheduler().Schedule(state, dueTime, action); | |
} | |
private IScheduler GetScheduler() | |
{ | |
return _dispatcherScheduler.Dispatcher.CheckAccess() ? (IScheduler)_immediateScheduler : (IScheduler)_dispatcherScheduler; | |
} | |
public DateTimeOffset Now { get { return _dispatcherScheduler.Now; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment