Boz*_*Joe 1 c# multithreading asynchronous .net-3.5
在.net 3.5
尝试ThreadPool.QueueUserWorkItem(a=> {Work()});在ThreadPool没有可用线程时导致BeginInvoke锁定.
void Work()
{
Action executor = () = { DoSomething(); };
IAsyncResult result = executor.BeginInvoke(null, null);
using (WaitHandle hWait = result.AsyncWaitHandle)
{
if (hWait.WaitOne(timeoutMilliseconds))
{
executor.EndInvoke(result);
}
else
{ throw new ImDyingException(); }
}
}
Run Code Online (Sandbox Code Playgroud)
如何使BeginInvoke使用非池化线程?
| 归档时间: |
|
| 查看次数: |
2592 次 |
| 最近记录: |