It's not usually recommended to use Task.Run to convert a synchronous method to an async Task, especially if you're going to immediately await that Task: Should I expose asynchronous wrappers for synchronous methods? | Stephen Toub[^] Instead, it's better to push the asynchronous operation down, and make the method your calling return a Task. Also, when you're using async, you should try to avoid Thread.Sleep; use await Task.Delay(...) instead: Visual C#: Thread.Sleep vs. Task.Delay[^] And as Agent__007 said, if you want both methods to run in parallel, you need to use Task.WhenAll to wait for them.
protected async void btnSubmit_Click(object sender, EventArgs e)
{
Response.Write(DateTime.Now.ToString("dd-MM-yyyy:hh:mm:ss") + " <br/>");
Task first = dowork();
Task second = DoAnotherWork();
await Task.WhenAll(first, second);
Response.Write(DateTime.Now.ToString("dd-MM-yyyy:hh:mm:ss") + " <br/>");
}
async Task dowork()
{
await Task.Delay(5000);
}
async Task DoAnotherWork()
{
await Task.Delay(3000);
}
Since you're using ASP.NET WebForms, you should consider using the RegisterAsyncTask method[^] to run your async code, and avoid using async void where possible: Using Asynchronous Methods in ASP.NET 4.5[^]