本文整理汇总了C#中ContextCallback类的典型用法代码示例。如果您正苦于以下问题:C# ContextCallback类的具体用法?C# ContextCallback怎么用?C# ContextCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContextCallback类属于命名空间,在下文中一共展示了ContextCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: GetPostActionCallback
private static ContextCallback GetPostActionCallback()
{
var callback = _postActionCallback;
if (callback == null)
{
// lazily initialize SecurityCritical delegate
_postActionCallback = callback = PostAction;
}
return callback;
}
示例3: PartialTrustInvoke
internal static void PartialTrustInvoke(ContextCallback callback, object state)
{
if (NeedPartialTrustInvoke)
{
SecurityContext.Run(aspNetSecurityContext.CreateCopy(), callback, state);
}
else
{
callback(state);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例12: CallbackEntry
public CallbackEntry(int number, int range, ContextCallback callback)
: base(number, range)
{
m_Callback = callback;
}
示例13: ExecutionContextRunData
internal ExecutionContextRunData(ExecutionContext executionContext, ContextCallback cb, Object state)
{
this.ec = executionContext;
this.callBack = cb;
this.state = state;
ecsw = new ExecutionContextSwitcher();
}
示例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);
}
示例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
}
}
}