I thought the GetData task registered in Page_Load won't block the loading of Index.aspx, since it's an async task; 5 seconds after the page is rendered, the lblData is set and reflected on the Index.aspx.
However, in my case, the loading of Index.aspx is blocked for 5 seconds, waiting for the async GetData to be finished. Only after 5 seconds is the Index.aspx rendered.
Is this expected? Or the GetData is running synchronously because I did something wrong?
// Index.aspx.cs
public partial class Index : Page
{
protected string lblData;
protected void Page_Load(object sender, EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(GetData));
ExecuteRegisteredAsyncTasks();
}
public async Task GetData()
{
await Task.Delay(5000);
lblData = "Hello world!";
}
// ...
}
I've added Async="true" to Index.aspx.