Page_Load()
方法可以是async
?我问,如果我已经宣布这样Can Page_Load()Be Async
protected void Page_Load()
一切都加载,因为它应该。如果我把它宣布为
protected async void Page_Load()
的Page_Load()
断点不会打,也不会在catch()
块被击中。
现在我正在尝试将Page_Load()
方法设置为async
,以便在页面完全呈现前执行3个不同的存储过程。如果我没有我的Page_Load()
方法async
我得到这个编译错误:
The await operator can only be used with an async method.
我的代码是这样。
private DataSet ds1 = new DataSet();
private DataSet ds2 = new DataSet();
private DataSet ds3 = new DataSet();
protected async void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var task1 = GetStoreInfo();
var task2 = GetSalespersonInfo();
var task3 = GetManagerInfo();
await System.Threading.Tasks.Task.WhenAll(task1, task2, task3);
PopulateAll();
}
}
async System.Threading.Tasks.Task<DataSet> GetStoreInfo()
{
ds1 = RunStoredProcedureToReturnThisData();
return ds1;
}
async System.Threading.Tasks.Task<DataSet> GetSalespersonInfo()
{
ds2 = RunStoredProcedureToReturnThisData();
return ds2;
}
async System.Threading.Tasks.Task<DataSet> GetManagerInfo()
{
ds3 = RunStoredProcedureToReturnThisData();
return ds3;
}
protected void PopulateAll()
{
//Bind the different returned datasets
}
This present m e调试错误为:错误解析属性'async':类型'AsyncTest.Page1'没有名为'async'的公共属性 –