Skip to content

Instantly share code, notes, and snippets.

@duongphuhiep
Last active January 19, 2016 17:09
Show Gist options
  • Save duongphuhiep/f83f98593d93045e717f to your computer and use it in GitHub Desktop.
Save duongphuhiep/f83f98593d93045e717f to your computer and use it in GitHub Desktop.
WinForm: Display BusyForm then run Long Operation on background
private void compareBtn_Click(object sender, EventArgs e)
{
try
{
var busyForm = new BusyForm();
busyForm.Shown += async (sd, args) =>
{
try
{
//Init GUI before launch
this.outputEdt.Text = "start";
await Task.Run(() =>
{
RunLongOperation();
});
//Display result to GUI after launch
this.outputEdt.Text = "finish";
}
catch (Exception ex)
{
Log.Error(ex);
errorReporter.Show(ex);
}
finally
{
busyForm.Close();
}
};
busyForm.ShowDialog(this);
}
catch (Exception ex)
{
Log.Error(ex);
errorReporter.Show(ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment