145
|
1 using System;
|
|
2
|
|
3 namespace Implab {
|
|
4 public interface ICancellationToken {
|
|
5 /// <summary>
|
|
6 /// Indicates wherther the cancellation was requested.
|
|
7 /// </summary>
|
|
8 bool IsCancellationRequested { get ; }
|
|
9
|
|
10 /// <summary>
|
|
11 /// The reason why the operation should be cancelled.
|
|
12 /// </summary>
|
|
13 Exception CancellationReason { get ; }
|
|
14
|
|
15 /// <summary>
|
|
16 /// Accepts if requested.
|
|
17 /// </summary>
|
|
18 /// <returns><c>true</c>, if if requested was accepted, <c>false</c> otherwise.</returns>
|
|
19 bool CancelOperationIfRequested();
|
|
20
|
|
21 /// <summary>
|
|
22 /// Sets the token to cancelled state.
|
|
23 /// </summary>
|
|
24 /// <param name="reason">The reason why the operation was cancelled.</param>
|
|
25 void CancelOperation(Exception reason);
|
|
26
|
|
27 /// <summary>
|
|
28 /// Adds the listener for the cancellation request, is the cancellation was requested the <paramref name="handler"/>
|
|
29 /// is executed immediatelly.
|
|
30 /// </summary>
|
|
31 /// <param name="handler">The handler which will be executed if the cancel occurs.</param>
|
|
32 void CancellationRequested(Action<Exception> handler);
|
|
33
|
|
34 }
|
|
35 }
|
|
36
|