【发布时间】:2015-05-10 09:46:16
【问题描述】:
在 Stephan Cleary 最近关于Async Console Apps on .NET CoreCLR 的博文中,他向我们展示了在CoreCLR(目前在Visual Studio 2015,CTP6 上运行)中,入口点“Main”实际上可以标记为async Task,正确编译并实际运行:
public class Program
{
public async Task Main(string[] args)
{
Console.WriteLine("Hello World");
await Task.Delay(TimeSpan.FromSeconds(1));
Console.WriteLine("Still here!");
Console.ReadLine();
}
}
给出以下输出:
ASP.NET 团队的一篇名为 A Deep Dive into the ASP.NET 5 Runtime 的博客文章强化了这一点:
除了静态的
Program.Main入口点,KRE 还支持 基于实例的入口点。您甚至可以制作主要入口点 异步并返回一个任务。通过让主入口点成为 实例方法,您可以将服务注入到您的应用程序中 运行时环境。
到目前为止,我们都知道这一点,An entry point cannot be marked with the 'async' modifier。那么,在新的 CoreCLR 运行时中,这实际上是如何实现的呢?
【问题讨论】:
标签: c# .net async-await coreclr