【发布时间】:2011-09-20 19:35:00
【问题描述】:
我第一次玩 async CTP...(很好)大约 15 分钟。
这是我拼凑的一个非常简单的服务器:
internal class Server
{
private HttpListener listener;
public Server()
{
listener = new HttpListener();
listener.Prefixes.Add("http://*:80/asynctest/");
listener.Start();
Go();
}
async void Go()
{
HttpListenerContext context = await listener.GetContextAsync();
Go();
using (var httpListenerResponse = context.Response)
using (var outputStream = httpListenerResponse.OutputStream)
using (var sw = new StreamWriter(outputStream))
{
await sw.WriteAsync("hello world");
}
}
}
可以看出,异步方法Go 调用自己。在经典的非异步世界中,这会导致堆栈溢出。我认为异步方法不是这种情况,但我想确定,一种或另一种方式。有人吗?
【问题讨论】: