我有两个选择:
while (true) {
var socket = tcpListener.Accept();
Task.Run(async () => await RunConnectionAsync(socket));
}
while (true)
{
allDone.Reset();
tcpListener.BeginAcceptSocket(AcceptCallback, tcpListener);
allDone.WaitOne();
}
private static void AcceptCallback(IAsyncResult result)
{
allDone.Set();
var listener = (TcpListener)result.AsyncState;
var socket = listener.EndAcceptSocket(result);
ProcessSocket(socket);
}
就性能而言,哪种解决方案更好?