本文整理汇总了C#中WaitCallback.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# WaitCallback.BeginInvoke方法的具体用法?C# WaitCallback.BeginInvoke怎么用?C# WaitCallback.BeginInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WaitCallback
的用法示例。
在下文中一共展示了WaitCallback.BeginInvoke方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main ()
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
throw new Exception ("From the threadpoool");
});
wcb.BeginInvoke (wcb, OnCBFinished, null);
Thread.Sleep (1000);
return 1;
}
示例2: Main
static int Main ()
{
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
Thread.CurrentThread.Abort ();
});
wcb.BeginInvoke (wcb, null, null);
Thread.Sleep (1000);
return 0;
}
示例3: Main
static int Main ()
{
monitor = new object ();
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
WaitCallback wcb = new WaitCallback ((a) => {
Thread.CurrentThread.Abort();
});
wcb.BeginInvoke (wcb, OnCBFinished, null);
lock (monitor) {
Monitor.Wait (monitor);
}
Thread.Sleep (1000);
return 1;
}
示例4: QueueUserWorkItem
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
if (callBack == null)
throw new ArgumentNullException ("callBack");
if (callBack.IsTransparentProxy ()) {
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} else {
AsyncResult ares = new AsyncResult (callBack, state, true);
pool_queue (ares);
}
return true;
}
示例5: QueueUserWorkItem
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
if (callBack == null)
throw new ArgumentNullException ("callBack");
#if MOONLIGHT
callBack = MoonlightHandler (callBack);
#endif
if (callBack.IsTransparentProxy ()) {
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} else {
if (!callBack.HasSingleTarget)
throw new Exception ("The delegate must have only one target");
AsyncResult ares = new AsyncResult (callBack, state, true);
pool_queue (ares);
}
return true;
}
示例6: UnsafeQueueUserWorkItem
public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
{
// no stack propagation here (that's why it's unsafe and requires extra security permissions)
if (!callBack.IsTransparentProxy ()) {
if (!callBack.HasSingleTarget)
throw new Exception ("The delegate must have only one target");
AsyncResult ares = new AsyncResult (callBack, state, false);
pool_queue (ares);
return true;
}
try {
if (!ExecutionContext.IsFlowSuppressed ())
ExecutionContext.SuppressFlow (); // on current thread only
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} finally {
if (ExecutionContext.IsFlowSuppressed ())
ExecutionContext.RestoreFlow ();
}
return true;
}
示例7: UnsafeQueueUserWorkItem
public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
{
if (Microsoft.ThreadPool.UseMicrosoftThreadPool) {
return Microsoft.ThreadPool.UnsafeQueueUserWorkItem (callBack, state);
} else {
if (callBack == null)
throw new ArgumentNullException ("callBack");
// no stack propagation here (that's why it's unsafe and requires extra security permissions)
if (!callBack.IsTransparentProxy ()) {
AsyncResult ares = new AsyncResult (callBack, state, false);
pool_queue (ares);
return true;
}
try {
if (!ExecutionContext.IsFlowSuppressed ())
ExecutionContext.SuppressFlow (); // on current thread only
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} finally {
if (ExecutionContext.IsFlowSuppressed ())
ExecutionContext.RestoreFlow ();
}
return true;
}
}
示例8: QueueUserWorkItem
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
if (Microsoft.ThreadPool.UseMicrosoftThreadPool) {
return Microsoft.ThreadPool.QueueUserWorkItem (callBack, state);
} else {
if (callBack == null)
throw new ArgumentNullException ("callBack");
if (callBack.IsTransparentProxy ()) {
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
} else {
AsyncResult ares = new AsyncResult (callBack, state, !ExecutionContext.IsFlowSuppressed());
pool_queue (ares);
}
return true;
}
}
示例9: QueueUserWorkItem
public static bool QueueUserWorkItem (WaitCallback callBack, object state)
{
if (callBack == null)
throw new ArgumentNullException ("callBack");
#if NET_2_1 && !MONOTOUCH
callBack = MoonlightHandler (callBack);
#endif
IAsyncResult ar = callBack.BeginInvoke (state, null, null);
if (ar == null)
return false;
return true;
}
示例10: UnsafeQueueUserWorkItem
public static bool UnsafeQueueUserWorkItem (WaitCallback callBack, object state)
{
// no stack propagation here (that's why it's unsafe and requires extra security permissions)
IAsyncResult ar = null;
try {
if (!ExecutionContext.IsFlowSuppressed ())
ExecutionContext.SuppressFlow (); // on current thread only
ar = callBack.BeginInvoke (state, null, null);
}
finally {
if (ExecutionContext.IsFlowSuppressed ())
ExecutionContext.RestoreFlow ();
}
return (ar != null);
}
示例11: OnBegin
//异步页面的任务启动方法
public IAsyncResult OnBegin(object sender, EventArgs e,
AsyncCallback cb, object extraData)
{
_proc = new WaitCallback(ChatInvokeProc);
Hashtable theUser = new Hashtable();
theUser = (Hashtable)extraData;
string user = theUser["guid"].ToString();
_guid = user;
Thread.CurrentThread.Name = "上下文线程" + user;
//用户处理,不存在则增加,即为登录
theUser["asyn"] = this;
theUser["lastUpdateTime"] = DateTime.Now.ToString();
Hashtable feachUser = new Hashtable();
bool isInCach=false;
for (var i = 0; i < globalCache.userCache.Count; i++)
{
feachUser = (Hashtable)globalCache.userCache[i];
if (theUser["guid"].ToString() == feachUser["guid"].ToString())
{
globalCache.userCache[i] = theUser;
isInCach = true;
}
}
if (!isInCach)
{
globalCache.userCache.Add(theUser);
}
//开始异步执行,这里会开启一个新的辅助线程
return _proc.BeginInvoke(extraData, cb, extraData);
}