Last active
January 19, 2016 17:09
-
-
Save duongphuhiep/f83f98593d93045e717f to your computer and use it in GitHub Desktop.
WinForm: Display BusyForm then run Long Operation on background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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