本文整理汇总了C#中SendOrPostCallback.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# SendOrPostCallback.Invoke方法的具体用法?C# SendOrPostCallback.Invoke怎么用?C# SendOrPostCallback.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SendOrPostCallback
的用法示例。
在下文中一共展示了SendOrPostCallback.Invoke方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public override void Send(SendOrPostCallback d, object state)
{
SynchronizationContext oldContext = SynchronizationContext.Current;
SynchronizationContext.SetSynchronizationContext(this);
d.Invoke(state);
SynchronizationContext.SetSynchronizationContext(oldContext);
}
示例2: Post
/// <summary>
/// Dispatch a single job to the target thread and return immediately.
/// This method can be called in background thread.
/// </summary>
/// <param name="callback">The callback which you wants to dispatch</param>
public override void Post(SendOrPostCallback callback, object state)
{
jobs.Add(() =>
{
callback.Invoke(state);
});
}
示例3: Send
public override void Send(SendOrPostCallback d, object state)
{
if (_thread == Thread.CurrentThread)
d.Invoke(state);
else
throw new NotSupportedException("Synchronously sending from different threads is not supported.");
}
示例4: Post
public override void Post(SendOrPostCallback d, object state)
{
synchronizationImplementation.Post(passedState =>
{
SetSynchronizationContext(this);
cultureHolder.ApplyCulture();
d.Invoke(passedState);
}, state);
}
示例5: Post
public override void Post(SendOrPostCallback callback, object state)
{
Server.CallFuncEvent e = new Server.CallFuncEvent(() =>
{
callback.Invoke(state);
});
server.Enqueue(e);
}
示例6: Post
public override void Post(SendOrPostCallback d, object state)
{
ThreadPool.QueueUserWorkItem(_ =>
{
SynchronizationContext oldContext = SynchronizationContext.Current;
SynchronizationContext.SetSynchronizationContext(this);
d.Invoke(state);
SynchronizationContext.SetSynchronizationContext(oldContext);
}, null);
}
示例7: Send
public override void Send (SendOrPostCallback d, object state)
{
if (Application.UIThread != null && Application.UIThread.ManagedThreadId != Thread.CurrentThread.ManagedThreadId) {
var evt = new ManualResetEventSlim (false);
Exception exception = null;
Application.Invoke (() => {
try {
d.Invoke (state);
} catch (Exception ex) {
exception = ex;
} finally {
Thread.MemoryBarrier ();
evt.Set ();
}
});
evt.Wait ();
if (exception != null)
throw exception;
} else {
d.Invoke (state);
}
}
示例8: Send
public override void Send (SendOrPostCallback d, object state)
{
Exception ex = null;
using (var waiter = new ManualResetEventSlim (false)) {
Post (wrapper => {
try {
d.Invoke (state);
} catch (Exception e) {
ex = e;
} finally {
waiter.Set ();
}
}, null);
waiter.Wait ();
}
if (ex != null)
throw ex;
}
示例9: RunInSafeContext
private void RunInSafeContext(SendOrPostCallback core)
{
if (UiSynchronizationContext != null)
{
UiSynchronizationContext.Send(core, null);
}
else
{
core.Invoke(null);
}
}
示例10: Send
/// <summary>
/// Dispatch a single job to the target thread and wait until the job ends.
/// This method can be called in background thread.
/// </summary>
/// <param name="callback">The callback which you wants to dispatch</param>
public override void Send(SendOrPostCallback callback, object state)
{
AutoResetEvent ev = new AutoResetEvent(false);
jobs.Add(() =>
{
callback.Invoke(state);
ev.Set();
});
ev.WaitOne();
}
示例11: Post
public override void Post(SendOrPostCallback d, object state)
{
d.Invoke(state);
}
示例12: Post
public override void Post (SendOrPostCallback d, object state)
{
Application.Invoke (() => d.Invoke (state));
}
示例13: Send
public override void Send (SendOrPostCallback d, object state)
{
var evt = new ManualResetEventSlim (false);
Exception exception = null;
Post (s => {
try {
d.Invoke (state);
} catch (Exception ex) {
exception = ex;
} finally {
Thread.MemoryBarrier ();
evt.Set ();
}
}, null);
evt.Wait ();
if (exception != null)
throw exception;
}
示例14: Post
public override void Post(SendOrPostCallback d, object state)
{
_dispatcher.BeginInvoke(() => d.Invoke(state));
}