11 [DebuggerDisplay(
"IsCancellationRequested = {IsCancellationRequested}")]
12 [__DynamicallyInvokable]
13 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
18 private static readonly Action<object> s_ActionToActionObjShunt = ActionToActionObjShunt;
22 [__DynamicallyInvokable]
25 [__DynamicallyInvokable]
35 [__DynamicallyInvokable]
38 [__DynamicallyInvokable]
52 [__DynamicallyInvokable]
55 [__DynamicallyInvokable]
60 return m_source.CanBeCanceled;
69 [__DynamicallyInvokable]
72 [__DynamicallyInvokable]
77 InitializeDefaultSource();
79 return m_source.WaitHandle;
90 [__DynamicallyInvokable]
100 private static void ActionToActionObjShunt(
object obj)
112 [__DynamicallyInvokable]
115 if (callback ==
null)
119 return Register(s_ActionToActionObjShunt, callback, useSynchronizationContext:
false, useExecutionContext:
true);
129 [__DynamicallyInvokable]
132 if (callback ==
null)
136 return Register(s_ActionToActionObjShunt, callback, useSynchronizationContext, useExecutionContext:
true);
146 [__DynamicallyInvokable]
149 if (callback ==
null)
153 return Register(callback, state, useSynchronizationContext:
false, useExecutionContext:
true);
164 [__DynamicallyInvokable]
167 return Register(callback, state, useSynchronizationContext, useExecutionContext:
true);
172 return Register(callback, state, useSynchronizationContext:
false, useExecutionContext:
false);
176 [SecuritySafeCritical]
177 private CancellationTokenRegistration
Register(Action<object> callback,
object state,
bool useSynchronizationContext,
bool useExecutionContext)
179 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
180 if (callback ==
null)
186 return default(CancellationTokenRegistration);
188 SynchronizationContext targetSyncContext =
null;
189 ExecutionContext executionContext =
null;
192 if (useSynchronizationContext)
194 targetSyncContext = SynchronizationContext.Current;
196 if (useExecutionContext)
198 executionContext = ExecutionContext.Capture(ref stackMark, ExecutionContext.CaptureOptions.OptimizeDefaultCase);
201 return m_source.InternalRegister(callback, state, targetSyncContext, executionContext);
208 [__DynamicallyInvokable]
211 if (m_source ==
null && other.m_source ==
null)
215 if (m_source ==
null)
219 if (other.m_source ==
null)
223 return m_source == other.m_source;
231 [__DynamicallyInvokable]
232 public override bool Equals(
object other)
243 [__DynamicallyInvokable]
246 if (m_source ==
null)
250 return m_source.GetHashCode();
259 [__DynamicallyInvokable]
262 return left.
Equals(right);
271 [__DynamicallyInvokable]
274 return !left.
Equals(right);
280 [__DynamicallyInvokable]
285 ThrowOperationCanceledException();
289 internal void ThrowIfSourceDisposed()
291 if (m_source !=
null && m_source.IsDisposed)
293 ThrowObjectDisposedException();
297 private void ThrowOperationCanceledException()
299 throw new OperationCanceledException(Environment.GetResourceString(
"OperationCanceled"),
this);
302 private static void ThrowObjectDisposedException()
304 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"CancellationToken_SourceDisposed"));
307 private void InitializeDefaultSource()
309 m_source = CancellationTokenSource.InternalGetStaticSource(
set:
false);
CancellationTokenRegistration Register(Action callback, bool useSynchronizationContext)
Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Propagates notification that operations should be canceled.
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
void ThrowIfCancellationRequested()
Throws a T:System.OperationCanceledException if this token has had cancellation requested.
Represents a callback delegate that has been registered with a T:System.Threading....
override bool Equals(object other)
Determines whether the current T:System.Threading.CancellationToken instance is equal to the specifie...
bool CanBeCanceled
Gets whether this token is capable of being in the canceled state.
delegate void Action()
Encapsulates a method that has no parameters and does not return a value.
bool IsCancellationRequested
Gets whether cancellation has been requested for this token.
override int GetHashCode()
Serves as a hash function for a T:System.Threading.CancellationToken.
CancellationTokenRegistration Register(Action< object > callback, object state, bool useSynchronizationContext)
Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.
SecurityAction
Specifies the security actions that can be performed using declarative security.
CancellationToken(bool canceled)
Initializes the T:System.Threading.CancellationToken.
MethodImplOptions
Defines the details of how a method is implemented.
static CancellationToken None
Returns an empty T:System.Threading.CancellationToken value.
static bool operator==(CancellationToken left, CancellationToken right)
Determines whether two T:System.Threading.CancellationToken instances are equal.
CancellationTokenRegistration Register(Action< object > callback, object state)
Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.
Signals to a T:System.Threading.CancellationToken that it should be canceled.
bool Equals(CancellationToken other)
Determines whether the current T:System.Threading.CancellationToken instance is equal to the specifie...
static bool operator !=(CancellationToken left, CancellationToken right)
Determines whether two T:System.Threading.CancellationToken instances are not equal.
bool IsCancellationRequested
Gets whether cancellation has been requested for this T:System.Threading.CancellationTokenSource.
CancellationTokenRegistration Register(Action callback)
Registers a delegate that will be called when this T:System.Threading.CancellationToken is canceled.