Пример #1
0
        private void CancellationCallbackCoreWork(CancellationCallbackCoreWorkArguments args)
        {
            CancellationCallbackInfo cancellationCallbackInfo = args.m_currArrayFragment.SafeAtomicRemove(args.m_currArrayIndex, this.m_executingCallback);

            if (cancellationCallbackInfo == this.m_executingCallback)
            {
                if (cancellationCallbackInfo.TargetExecutionContext != null)
                {
                    cancellationCallbackInfo.CancellationTokenSource.ThreadIDExecutingCallbacks = Thread.CurrentThread.ManagedThreadId;
                }
                cancellationCallbackInfo.ExecuteCallback();
            }
        }
        private void CancellationCallbackCoreWork_OnSyncContext(object obj)
        {
            CancellationCallbackCoreWorkArguments arguments = (CancellationCallbackCoreWorkArguments)obj;
            CancellationCallbackInfo info = arguments.m_currArrayFragment.SafeAtomicRemove(arguments.m_currArrayIndex, this.m_executingCallback);

            if (info == this.m_executingCallback)
            {
                if (info.TargetExecutionContext != null)
                {
                    info.CancellationTokenSource.ThreadIDExecutingCallbacks = Thread.CurrentThread.ManagedThreadId;
                }
                info.ExecuteCallback();
            }
        }
        // The main callback work that executes on the target synchronization context
        private void CancellationCallbackCoreWork_OnSyncContext(object obj)
        {
            CancellationCallbackCoreWorkArguments args = (CancellationCallbackCoreWorkArguments)obj;

            // now remove the intended callback..and ensure that it worked.
            // otherwise the callback has disappeared in the interim and we can immediately return.
            CancellationCallbackInfo callback = args.m_currArrayFragment.SafeAtomicRemove(args.m_currArrayIndex, m_executingCallback);

            if (callback == m_executingCallback)
            {
                if (callback.TargetExecutionContext != null)
                {
                    // we are running via a custom sync context, so update the executing threadID
                    callback.CancellationTokenSource.ThreadIDExecutingCallbacks = Thread.CurrentThread.ManagedThreadId;
                }
                callback.ExecuteCallback();
            }
        }