I'm writing an async event handler for a windows form but I'm not experienced with the way C# handles certain scenarios, as closing the form during a async processing triggered by an async event handler in this case.
Closing the form in question does not terminate the whole program, as the form was initialized by another form (the "main" form).
That's what the code I'm writing looks like:
private void async btn_ButtonClick(...){
aLabel.Text = "Validating something ...";
var isValid = await IsSomethingValid(...);
if (isValid)
aLabel.Text = "It's valid";
else{
aLabel.Text = "Sending email ...";
await SendEmail(...);
aLabel.Text = "Email sent";
}
}
I've done some tests and even placing a long Thread.Sleep
in SendEmail
(before when it actually sends the email) and closing the form during that sleep the email ends up being sent.
Why is it so?
Would an async query also be executed even after closing its parent process?