我有这个代码:
public async virtual void Start(IPAddress ip, int port)
{
//Start listening proccess
Listener = new TcpListener(ip, port);
Listener.Start();
IsListening = true;
await Task.Run(async () =>
{
while (IsListening)
{
if (Listener.Pending())
{
TcpClient client = await Listener.AcceptTcpClientAsync();
SkyfilterClient sklient = new SkyfilterClient(client);
byte command = sklient.Reader.ReadByte();
if (command == (byte) SkyfilterCommand.Authenticate)
{
sklient = await Authenticate(sklient);
}
else if(command == (byte)SkyfilterCommand.Register)
{
sklient = await Register(sklient);
}
}
}
});
}
Program.cs 中的代码,主要方法
new SkyfilterCoreLib.Network.SkyfilterServer().Start(IPAddress.Loopback, 7812);
Console.ReadLine();
如果我有异步 lambda 是最好的吗?或者我只使用一项任务,让听众Listener.AcceptTcpClient
只使用?哪一个有最好的表现?谢谢