I am working on a winform Application that processes a very large excel file. During the execution it was freezing the UI. So, I found out about async and await in C# that can keep the UI responsive when performing long task. I have implemented them the following way -
This is working and my UI is also responsive. But I wanted to ask should I make ProcessExcel() also async?
Another thing that I have noticed. That when I am in the debugging using breakpoints, my UI is unresponsive. I wanted to find out what happens if someones accidentally closes the please wait form.
Though, I have figured out that nothing happens and the main form continues it execution as it.
My apologies for the basic questions, I have just discovered await and async.
C#:
private async void btnClick()
{
PleaseWait pleasewait = new PleaseWait();
pleasewait.Show();
// Perform your long-running task asynchronously
await Task.Run(() => ProcessExcel());
pleasewait.Close();
MessageBox.Show("Processing Complete!")
}
private void ProcessExcel()
{
//read excel file
//does some calculations on the rows
// write output in another excel file
}
This is working and my UI is also responsive. But I wanted to ask should I make ProcessExcel() also async?
Another thing that I have noticed. That when I am in the debugging using breakpoints, my UI is unresponsive. I wanted to find out what happens if someones accidentally closes the please wait form.
Though, I have figured out that nothing happens and the main form continues it execution as it.
My apologies for the basic questions, I have just discovered await and async.
Last edited: