在 ASP.NET 4.5 中有一个新的应用程序设置。
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
这样的代码可以在asp.net 4.0中运行
protected void Button1_Click(object sender, EventArgs e)
{
CallAysnc();
}
public void CallAysnc()
{
AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(Guid.NewGuid().ToString());
WebClient client = new WebClient();
client.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) =>
{
asyncOp.PostOperationCompleted(CallCompleted, e.Result);
};
client.DownloadStringAsync(new Uri("http://www.google.com"));
}
private void CallCompleted(object args)
{
Response.Write(args.ToString());
}
但是在asp.net 4.5中不起作用,当我移除新的appsetting后,它又起作用了!
那么"UseTaskFriendlySynchronizationContext"是什么意思?