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”是什么意思?