比如下面的代码,在 mres.Set() 没有被调用的时候,当前线程是不是会被一直阻塞(blocking)着?
var args = new SocketAsyncEventArgs();
using (var mres = new ManualResetEventSlim())
{
args.Completed += (s, e) => mres.Set();
if (socket.ConnectAsync(args))
{
if (!mres.Wait(timeout))
{
throw new TimeoutException("Could not connect to " + endpoint);
}
}
}如果会阻塞当前线程, mres.Wait 返回 false 时是不是会释放当前线程?
如果会阻塞当前线程,在 async 方法中使用会带来什么后果?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1377/viewspace-3150956/ ,如需转载,请注明出处,否则将追究法律责任。