public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action <object> callback, object state)
        {
            var callbackWrapper          = new CancellationCallbackWrapper(callback, state);
            var registration             = cancellationToken.Register(s => InvokeCallback(s), callbackWrapper);
            var disposeCancellationState = new DisposeCancellationState(callbackWrapper, registration);

            return(new DisposableAction(s => Dispose(s), disposeCancellationState));
        }
        public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action<object> callback, object state)
        {
            var callbackWrapper = new CancellationCallbackWrapper(callback, state);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            CancellationTokenRegistration registration = _tokenRegister(ref cancellationToken, s => InvokeCallback(s), callbackWrapper);

            var disposeCancellationState = new DiposeCancellationState(callbackWrapper, registration);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return new DisposableAction(s => Dispose(s), disposeCancellationState);
        }
예제 #3
0
        public static IDisposable SafeRegister(this CancellationToken cancellationToken, Action <object> callback, object state)
        {
            var callbackWrapper = new CancellationCallbackWrapper(callback, state);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            CancellationTokenRegistration registration = _tokenRegister(ref cancellationToken, s => InvokeCallback(s), callbackWrapper);

            var disposeCancellationState = new DiposeCancellationState(callbackWrapper, registration);

            // Ensure delegate continues to use the C# Compiler static delegate caching optimization.
            return(new DisposableAction(s => Dispose(s), disposeCancellationState));
        }
 public DiposeCancellationState(CancellationCallbackWrapper callbackWrapper, CancellationTokenRegistration registration)
 {
     _callbackWrapper = callbackWrapper;
     _registration = registration;
 }
예제 #5
0
 public DiposeCancellationState(CancellationCallbackWrapper callbackWrapper, CancellationTokenRegistration registration)
 {
     _callbackWrapper = callbackWrapper;
     _registration    = registration;
 }