Scheduler.Async.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if HAS_AWAIT
  3. using System.Reactive.Disposables;
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace System.Reactive.Concurrency
  7. {
  8. public static partial class Scheduler
  9. {
  10. /// <summary>
  11. /// Yields execution of the current work item on the scheduler to another work item on the scheduler.
  12. /// The caller should await the result of calling Yield to schedule the remainder of the current work item (known as the continuation).
  13. /// </summary>
  14. /// <param name="scheduler">Scheduler to yield work on.</param>
  15. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  16. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  17. public static SchedulerOperation Yield(this IScheduler scheduler)
  18. {
  19. if (scheduler == null)
  20. throw new ArgumentNullException("scheduler");
  21. return new SchedulerOperation(a => scheduler.Schedule(a), scheduler.GetCancellationToken());
  22. }
  23. /// <summary>
  24. /// Yields execution of the current work item on the scheduler to another work item on the scheduler.
  25. /// The caller should await the result of calling Yield to schedule the remainder of the current work item (known as the continuation).
  26. /// </summary>
  27. /// <param name="scheduler">Scheduler to yield work on.</param>
  28. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  29. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  30. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  31. public static SchedulerOperation Yield(this IScheduler scheduler, CancellationToken cancellationToken)
  32. {
  33. if (scheduler == null)
  34. throw new ArgumentNullException("scheduler");
  35. return new SchedulerOperation(a => scheduler.Schedule(a), cancellationToken);
  36. }
  37. /// <summary>
  38. /// Suspends execution of the current work item on the scheduler for the specified duration.
  39. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) after the specified duration.
  40. /// </summary>
  41. /// <param name="scheduler">Scheduler to yield work on.</param>
  42. /// <param name="dueTime">Time when the continuation should run.</param>
  43. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  44. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  45. public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime)
  46. {
  47. if (scheduler == null)
  48. throw new ArgumentNullException("scheduler");
  49. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
  50. }
  51. /// <summary>
  52. /// Suspends execution of the current work item on the scheduler for the specified duration.
  53. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) after the specified duration.
  54. /// </summary>
  55. /// <param name="scheduler">Scheduler to yield work on.</param>
  56. /// <param name="dueTime">Time when the continuation should run.</param>
  57. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  58. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  59. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  60. public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime, CancellationToken cancellationToken)
  61. {
  62. if (scheduler == null)
  63. throw new ArgumentNullException("scheduler");
  64. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
  65. }
  66. /// <summary>
  67. /// Suspends execution of the current work item on the scheduler until the specified due time.
  68. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) at the specified due time.
  69. /// </summary>
  70. /// <param name="scheduler">Scheduler to yield work on.</param>
  71. /// <param name="dueTime">Time when the continuation should run.</param>
  72. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  73. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  74. public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime)
  75. {
  76. if (scheduler == null)
  77. throw new ArgumentNullException("scheduler");
  78. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
  79. }
  80. /// <summary>
  81. /// Suspends execution of the current work item on the scheduler until the specified due time.
  82. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) at the specified due time.
  83. /// </summary>
  84. /// <param name="scheduler">Scheduler to yield work on.</param>
  85. /// <param name="dueTime">Time when the continuation should run.</param>
  86. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  87. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  88. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  89. public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime, CancellationToken cancellationToken)
  90. {
  91. if (scheduler == null)
  92. throw new ArgumentNullException("scheduler");
  93. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
  94. }
  95. /// <summary>
  96. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  97. /// </summary>
  98. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  99. /// <param name="scheduler">Scheduler to schedule work on.</param>
  100. /// <param name="state">State to pass to the asynchronous method.</param>
  101. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  102. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  103. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  104. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
  105. {
  106. if (scheduler == null)
  107. throw new ArgumentNullException("scheduler");
  108. if (action == null)
  109. throw new ArgumentNullException("action");
  110. return ScheduleAsync_<TState>(scheduler, state, action);
  111. }
  112. /// <summary>
  113. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  114. /// </summary>
  115. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  116. /// <param name="scheduler">Scheduler to schedule work on.</param>
  117. /// <param name="state">State to pass to the asynchronous method.</param>
  118. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  119. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  120. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  121. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  122. {
  123. if (scheduler == null)
  124. throw new ArgumentNullException("scheduler");
  125. if (action == null)
  126. throw new ArgumentNullException("action");
  127. return ScheduleAsync_<TState>(scheduler, state, action);
  128. }
  129. /// <summary>
  130. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  131. /// </summary>
  132. /// <param name="scheduler">Scheduler to schedule work on.</param>
  133. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  134. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  135. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  136. public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task> action)
  137. {
  138. if (scheduler == null)
  139. throw new ArgumentNullException("scheduler");
  140. if (action == null)
  141. throw new ArgumentNullException("action");
  142. return ScheduleAsync_(scheduler, default(object), (self, o, ct) => action(self, ct));
  143. }
  144. /// <summary>
  145. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  146. /// </summary>
  147. /// <param name="scheduler">Scheduler to schedule work on.</param>
  148. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  149. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  150. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  151. public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  152. {
  153. if (scheduler == null)
  154. throw new ArgumentNullException("scheduler");
  155. if (action == null)
  156. throw new ArgumentNullException("action");
  157. return ScheduleAsync_(scheduler, default(object), (self, o, ct) => action(self, ct));
  158. }
  159. /// <summary>
  160. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  161. /// </summary>
  162. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  163. /// <param name="scheduler">Scheduler to schedule work on.</param>
  164. /// <param name="state">State to pass to the asynchronous method.</param>
  165. /// <param name="dueTime">Relative time after which to execute the action.</param>
  166. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  167. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  168. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  169. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  170. {
  171. if (scheduler == null)
  172. throw new ArgumentNullException("scheduler");
  173. if (action == null)
  174. throw new ArgumentNullException("action");
  175. return ScheduleAsync_(scheduler, state, dueTime, action);
  176. }
  177. /// <summary>
  178. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  179. /// </summary>
  180. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  181. /// <param name="scheduler">Scheduler to schedule work on.</param>
  182. /// <param name="state">State to pass to the asynchronous method.</param>
  183. /// <param name="dueTime">Relative time after which to execute the action.</param>
  184. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  185. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  186. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  187. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  188. {
  189. if (scheduler == null)
  190. throw new ArgumentNullException("scheduler");
  191. if (action == null)
  192. throw new ArgumentNullException("action");
  193. return ScheduleAsync_(scheduler, state, dueTime, action);
  194. }
  195. /// <summary>
  196. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  197. /// </summary>
  198. /// <param name="scheduler">Scheduler to schedule work on.</param>
  199. /// <param name="dueTime">Relative time after which to execute the action.</param>
  200. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  201. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  202. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  203. public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task> action)
  204. {
  205. if (scheduler == null)
  206. throw new ArgumentNullException("scheduler");
  207. if (action == null)
  208. throw new ArgumentNullException("action");
  209. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  210. }
  211. /// <summary>
  212. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  213. /// </summary>
  214. /// <param name="scheduler">Scheduler to schedule work on.</param>
  215. /// <param name="dueTime">Relative time after which to execute the action.</param>
  216. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  217. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  218. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  219. public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  220. {
  221. if (scheduler == null)
  222. throw new ArgumentNullException("scheduler");
  223. if (action == null)
  224. throw new ArgumentNullException("action");
  225. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  226. }
  227. /// <summary>
  228. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  229. /// </summary>
  230. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  231. /// <param name="scheduler">Scheduler to schedule work on.</param>
  232. /// <param name="state">State to pass to the asynchronous method.</param>
  233. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  234. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  235. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  236. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  237. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  238. {
  239. if (scheduler == null)
  240. throw new ArgumentNullException("scheduler");
  241. if (action == null)
  242. throw new ArgumentNullException("action");
  243. return ScheduleAsync_(scheduler, state, dueTime, action);
  244. }
  245. /// <summary>
  246. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  247. /// </summary>
  248. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  249. /// <param name="scheduler">Scheduler to schedule work on.</param>
  250. /// <param name="state">State to pass to the asynchronous method.</param>
  251. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  252. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  253. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  254. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  255. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  256. {
  257. if (scheduler == null)
  258. throw new ArgumentNullException("scheduler");
  259. if (action == null)
  260. throw new ArgumentNullException("action");
  261. return ScheduleAsync_(scheduler, state, dueTime, action);
  262. }
  263. /// <summary>
  264. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  265. /// </summary>
  266. /// <param name="scheduler">Scheduler to schedule work on.</param>
  267. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  268. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  269. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  270. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  271. public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task> action)
  272. {
  273. if (scheduler == null)
  274. throw new ArgumentNullException("scheduler");
  275. if (action == null)
  276. throw new ArgumentNullException("action");
  277. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  278. }
  279. /// <summary>
  280. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  281. /// </summary>
  282. /// <param name="scheduler">Scheduler to schedule work on.</param>
  283. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  284. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  285. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  286. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  287. public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  288. {
  289. if (scheduler == null)
  290. throw new ArgumentNullException("scheduler");
  291. if (action == null)
  292. throw new ArgumentNullException("action");
  293. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  294. }
  295. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
  296. {
  297. return scheduler.Schedule(state, (self, s) => InvokeAsync(self, s, action));
  298. }
  299. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  300. {
  301. return scheduler.Schedule(state, (self, s) => InvokeAsync(self, s, action));
  302. }
  303. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  304. {
  305. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  306. }
  307. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  308. {
  309. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  310. }
  311. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  312. {
  313. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  314. }
  315. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  316. {
  317. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  318. }
  319. private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  320. {
  321. var c = new CancellationDisposable();
  322. var d = new SingleAssignmentDisposable();
  323. action(new CancelableScheduler(self, c.Token), s, c.Token).ContinueWith(t =>
  324. {
  325. if (t.IsCanceled)
  326. return;
  327. if (t.Exception != null)
  328. t.Exception.Handle(e => e is OperationCanceledException);
  329. d.Disposable = t.Result;
  330. }, TaskContinuationOptions.ExecuteSynchronously);
  331. return StableCompositeDisposable.Create(c, d);
  332. }
  333. private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task> action)
  334. {
  335. return InvokeAsync(self, s, (self_, state, ct) => action(self_, state, ct).ContinueWith(_ => Disposable.Empty));
  336. }
  337. private static CancellationToken GetCancellationToken(this IScheduler scheduler)
  338. {
  339. var cs = scheduler as CancelableScheduler;
  340. return cs != null ? cs.Token : CancellationToken.None;
  341. }
  342. class CancelableScheduler : IScheduler
  343. {
  344. private readonly IScheduler _scheduler;
  345. private readonly CancellationToken _cancellationToken;
  346. public CancelableScheduler(IScheduler scheduler, CancellationToken cancellationToken)
  347. {
  348. _scheduler = scheduler;
  349. _cancellationToken = cancellationToken;
  350. }
  351. public CancellationToken Token
  352. {
  353. get { return _cancellationToken; }
  354. }
  355. public DateTimeOffset Now
  356. {
  357. get { return _scheduler.Now; }
  358. }
  359. public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
  360. {
  361. return _scheduler.Schedule(state, action);
  362. }
  363. public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
  364. {
  365. return _scheduler.Schedule(state, dueTime, action);
  366. }
  367. public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
  368. {
  369. return _scheduler.Schedule(state, dueTime, action);
  370. }
  371. }
  372. }
  373. }
  374. #endif