• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ContextCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ContextCallback的典型用法代码示例。如果您正苦于以下问题:C# ContextCallback类的具体用法?C# ContextCallback怎么用?C# ContextCallback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ContextCallback类属于命名空间,在下文中一共展示了ContextCallback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run(CompressedStack compressedStack, ContextCallback callback, object state)
        {
            if (compressedStack == null)
            {
                throw new ArgumentNullException(nameof(compressedStack));
            }

            // The original code was not checking for a null callback and would throw NullReferenceException
            callback(state);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:CompressedStack.cs


示例2: GetPostActionCallback

 private static ContextCallback GetPostActionCallback()
 {
     var callback = _postActionCallback;
     if (callback == null)
     {
         // lazily initialize SecurityCritical delegate
         _postActionCallback = callback = PostAction;
     }
     return callback;
 }
开发者ID:mesheets,项目名称:Theraot-CF,代码行数:10,代码来源:SynchronizationContextAwaitTaskContinuation.cs


示例3: PartialTrustInvoke

 internal static void PartialTrustInvoke(ContextCallback callback, object state)
 {
     if (NeedPartialTrustInvoke)
     {
         SecurityContext.Run(aspNetSecurityContext.CreateCopy(), callback, state);
     }
     else
     {
         callback(state);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:AspNetPartialTrustHelpers.cs


示例4: ExecuteCallback

 internal void ExecuteCallback()
 {
     if (TargetExecutionContext != null)
     {
         var callback = s_executionContextCallback;
         if (callback == null)
             s_executionContextCallback = callback = new ContextCallback(CancellationCallbackInfo.ExecutionContextCallback);
         ExecutionContext.Run(this.TargetExecutionContext, callback, this);
     }
     else
         ExecutionContextCallback(this);
 }
开发者ID:BclEx,项目名称:BclEx-Extend,代码行数:12,代码来源:CancellationCallbackInfo.cs


示例5: Run

 /// <summary>
 /// Runs a method in a specified execution context on the current thread.
 /// </summary>
 public static void Run(ExecutionContext context, ContextCallback callback, object state)
 {
     var syncContext = SynchronizationContext.Current;
     try
     {
         SynchronizationContext.SetSynchronizationContext(context.m_synchronizationContext);
         callback(state);
     }
     finally
     {
         SynchronizationContext.SetSynchronizationContext(syncContext);
     }
 }
开发者ID:ddunkin,项目名称:PortableContrib,代码行数:16,代码来源:ExecutionContext.cs


示例6: Enqueue

 /// <summary>
 /// The Enqueue method is invoked to add a callback action
 /// to the sequencer's queue of operations.
 /// </summary>
 /// <param name="callback">
 /// The callback that is to be invoked.
 /// </param>
 /// <param name="state">
 /// The state information to be passed to the callback
 /// method when it is executed.
 /// </param>
 public void Enqueue(ContextCallback callback, object state)
 {
     SequencedTask task = new SequencedTask(callback, state, ExecutionContext.Capture());
     lock (_taskQueue)
     {
         _taskQueue.Enqueue(task);
         if (_pending == false)
         {
             _pending = true;
             ThreadPool.UnsafeQueueUserWorkItem(Execute, null);
         }
     }
 }
开发者ID:recurry,项目名称:VersaFix,代码行数:24,代码来源:VfxSequencer.cs


示例7: ExecuteCallback

 internal void ExecuteCallback()
 {
     if (this.TargetExecutionContext != null)
     {
         ContextCallback contextCallback = CancellationCallbackInfo.s_executionContextCallback;
         if (contextCallback == null)
         {
             contextCallback = (CancellationCallbackInfo.s_executionContextCallback = new ContextCallback(CancellationCallbackInfo.ExecutionContextCallback));
         }
         ExecutionContext.Run(this.TargetExecutionContext, contextCallback, this);
         return;
     }
     CancellationCallbackInfo.ExecutionContextCallback(this);
 }
开发者ID:rmc00,项目名称:gsf,代码行数:14,代码来源:CancellationCallbackInfo.cs


示例8: Run

        public static void Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        {
            ExecutionContextSwitcher ecsw = default(ExecutionContextSwitcher);
            try
            {
                EstablishCopyOnWriteScope(ref ecsw);

                ExecutionContext.Restore(executionContext);
                callback(state);
            }
            catch
            {
                // Note: we have a "catch" rather than a "finally" because we want
                // to stop the first pass of EH here.  That way we can restore the previous
                // context before any of our callers' EH filters run.  That means we need to 
                // end the scope separately in the non-exceptional case below.
                ecsw.Undo();
                throw;
            }
            ecsw.Undo();
        }
开发者ID:l1183479157,项目名称:coreclr,代码行数:21,代码来源:ExecutionContext.cs


示例9: QueueUserWorkItem

 /// <summary>
 /// Queues a work item for processing on the managed thread pool
 /// </summary>
 /// <param name="callback">A WaitCallback representing the method to execute.</param>
 /// <param name="ctx">Alternate execution context in which to run the thread.</param>
 /// <returns>Reference to queued thread</returns>
 /// <remarks>
 /// This differs from the normal thread pool QueueUserWorkItem function in that it does
 /// not return a success value determing if item was queued, but rather a reference to
 /// to the managed thread that was actually placed on the queue.
 /// </remarks>
 public static ManagedThread QueueUserWorkItem(ContextCallback callback, ExecutionContext ctx)
 {
     return QueueUserWorkItem(callback, null, ctx);
 }
开发者ID:avs009,项目名称:gsf,代码行数:15,代码来源:ManagedThreadPool.cs


示例10: Run

		public static void Run (ExecutionContext executionContext, ContextCallback callback, object state)
		{
			if (executionContext == null) {
				throw new InvalidOperationException (Locale.GetText (
					"Null ExecutionContext"));
			}

			// FIXME: supporting more than one context should be done with executionContextSwitcher
			// and will requires a rewrite of this method
			var callContextCallBack = new ContextCallback (new Action<object> ((ostate) => {
				var originalCallContext = CallContext.CreateLogicalCallContext (true);
				try {
					CallContext.SetCurrentCallContext (executionContext.LogicalCallContext);
					callback (ostate);
				} finally {
					CallContext.SetCurrentCallContext (originalCallContext);
				}
			}));
			SecurityContext.Run (executionContext.SecurityContext, callContextCallBack, state);
		}
开发者ID:ramonsmits,项目名称:mono,代码行数:20,代码来源:ExecutionContext.cs


示例11: ManagedThread

 /// <summary>
 /// Initializes a new instance of the ManagedThread class, specifying a delegate that allows an object to be passed to the thread when the thread is started
 /// and allowing the user to specify an alternate execution context for the thread.
 /// </summary>
 public ManagedThread(ContextCallback callback, ExecutionContext ctx)
     : this(ThreadType.StandardThread, callback, null, ctx)
 {
     m_thread = new Thread(HandleItem);
 }
开发者ID:avs009,项目名称:gsf,代码行数:9,代码来源:ManagedThread.cs


示例12: CallbackEntry

 public CallbackEntry(int number, int range, ContextCallback callback)
     : base(number, range)
 {
     m_Callback = callback;
 }
开发者ID:brodock,项目名称:genova-project,代码行数:5,代码来源:PlayerMobile.cs


示例13: ExecutionContextRunData

 internal ExecutionContextRunData(ExecutionContext executionContext, ContextCallback cb, Object state)
 {
     this.ec = executionContext;
     this.callBack = cb;
     this.state = state;
     ecsw = new ExecutionContextSwitcher();
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:7,代码来源:executioncontext.cs


示例14: Run

        public static void Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        {
            if (executionContext == null)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullContext"));

            Thread currentThread = Thread.CurrentThread;
            ExecutionContextSwitcher ecsw = default(ExecutionContextSwitcher);
            try
            {
                EstablishCopyOnWriteScope(currentThread, ref ecsw);
                ExecutionContext.Restore(currentThread, executionContext);
                callback(state);
            }
            catch
            {
                // Note: we have a "catch" rather than a "finally" because we want
                // to stop the first pass of EH here.  That way we can restore the previous
                // context before any of our callers' EH filters run.  That means we need to 
                // end the scope separately in the non-exceptional case below.
                ecsw.Undo(currentThread);
                throw;
            }
            ecsw.Undo(currentThread);
        }
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:24,代码来源:ExecutionContext.cs


示例15: CallCallback

 internal void CallCallback()
 {
     // call directly if EC flow is suppressed
     if (m_executionContext == null)
     {
         m_timerCallback(m_state);
     }
     else
     {
         using (ExecutionContext executionContext = 
             m_executionContext.IsPreAllocatedDefault ? m_executionContext : m_executionContext.CreateCopy())
         {
             ContextCallback callback = s_callCallbackInContext;
             if (callback == null)
                 s_callCallbackInContext = callback = new ContextCallback(CallCallbackInContext);
             
             ExecutionContext.Run(
                 executionContext,
                 callback,
                 this,  // state
                 true); // ignoreSyncCtx
         }
     }
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:24,代码来源:Timer.cs


示例16: FinishPhase

        /// <summary>
        /// Finish the phase by invoking the post phase action, and setting the event, this must be called by the 
        /// last arrival thread
        /// </summary>
        /// <param name="observedSense">The current phase sense</param>
        private void FinishPhase(bool observedSense)
        {
            // Execute the PHA in try/finally block to reset the variables back in case of it threw an exception
            if (_postPhaseAction != null)
            {
                try
                {
                    // Capture the caller thread ID to check if the Add/RemoveParticipant(s) is called from the PHA
                    _actionCallerID = Environment.CurrentManagedThreadId;
                    if (_ownerThreadContext != null)
                    {
                        var currentContext = _ownerThreadContext;

                        ContextCallback handler = s_invokePostPhaseAction;
                        if (handler == null)
                        {
                            s_invokePostPhaseAction = handler = InvokePostPhaseAction;
                        }
                        ExecutionContext.Run(_ownerThreadContext, handler, this);
                    }
                    else
                    {
                        _postPhaseAction(this);
                    }

                    _exception = null; // reset the exception if it was set previously
                }
                catch (Exception ex)
                {
                    _exception = ex;
                }
                finally
                {
                    _actionCallerID = 0;
                    SetResetEvents(observedSense);
                    if (_exception != null)
                        throw new BarrierPostPhaseException(_exception);
                }
            }
            else
            {
                SetResetEvents(observedSense);
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:49,代码来源:Barrier.cs


示例17: CompleteWithCallback

        internal unsafe static void CompleteWithCallback(uint errorCode, uint bytesWritten, Win32ThreadPoolNativeOverlapped* overlapped)
        {
            OverlappedData data = overlapped->Data;

            Debug.Assert(!data._completed);
            data._completed = true;

            ContextCallback callback = s_executionContextCallback;
            if (callback == null)
                s_executionContextCallback = callback = OnExecutionContextCallback;

            // Get an args object from the per-thread cache.
            ExecutionContextCallbackArgs args = t_executionContextCallbackArgs;
            if (args == null)
                args = new ExecutionContextCallbackArgs();

            t_executionContextCallbackArgs = null;

            args._errorCode = errorCode;
            args._bytesWritten = bytesWritten;
            args._overlapped = overlapped;
            args._data = data;

            ExecutionContext.Run(data._executionContext, callback, args);
        }
开发者ID:GeneralRookie,项目名称:corefx,代码行数:25,代码来源:Win32ThreadPoolNativeOverlapped.cs


示例18: Run

        public static void Run(ExecutionContext executionContext, ContextCallback callback,  Object state)
        {
            if (executionContext == null )
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullContext"));
            }

            if (!executionContext.isNewCapture)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }
            
            executionContext.isNewCapture = false;
            
            ExecutionContext ec = Thread.CurrentThread.GetExecutionContextNoCreate();
            if ( (ec == null || ec.IsDefaultFTContext()) && SecurityContext.CurrentlyInDefaultFTSecurityContext(ec)
                && executionContext.IsDefaultFTContext())
            {
                callback(state);
            }
            else
            {
                RunInternal(executionContext, callback, state);
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:25,代码来源:executioncontext.cs


示例19: Run

        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public static void Run(SecurityContext securityContext, ContextCallback callback, Object state)
        {
            if (securityContext == null )
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NullContext"));
            }
            Contract.EndContractBlock();

            StackCrawlMark stackMark = StackCrawlMark.LookForMe;

            if (!securityContext.isNewCapture)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotNewCaptureContext"));
            }

            securityContext.isNewCapture = false;
#if !MOBILE
            ExecutionContext.Reader ec = Thread.CurrentThread.GetExecutionContextReader();
            
            // Optimization: do the callback directly if both the current and target contexts are equal to the
            // default full-trust security context
            if ( SecurityContext.CurrentlyInDefaultFTSecurityContext(ec)
                && securityContext.IsDefaultFTSecurityContext())
            {
                callback(state);
                
                if (GetCurrentWI(Thread.CurrentThread.GetExecutionContextReader()) != null) 
                {
                    // If we enter here it means the callback did an impersonation
                    // that we need to revert.
                    // We don't need to revert any other security state since it is stack-based 
                    // and automatically goes away when the callback returns.
                    WindowsIdentity.SafeRevertToSelf(ref stackMark);
                    // Ensure we have reverted to the state we entered in.
                    Contract.Assert(GetCurrentWI(Thread.CurrentThread.GetExecutionContextReader()) == null);
                }
            }
            else
#endif
            {
                RunInternal(securityContext, callback, state);
            }

        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:45,代码来源:securitycontext.cs


示例20: SecurityContextRunData

 internal SecurityContextRunData(SecurityContext securityContext, ContextCallback cb, Object state)
 {
     this.sc = securityContext;
     this.callBack = cb;
     this.state = state;
     this.scsw = new SecurityContextSwitcher();
 }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:securitycontext.cs



注:本文中的ContextCallback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ContextHandle类代码示例发布时间:2022-05-24
下一篇:
C# Context类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap