SmtpClient client = new SmtpClient("my.server.com");
I am creating the client as usual and send an email. All works fine, the email arrives in the box correctly.
Still i want to do some work in code inside the SendCompleted event handler.
client.SendCompleted += client_SendCompleted;
I'm starting the work without the async option,
client.Send(message);
but this way, my handler code is never hit.
If i choose client.SendAsync(), the event handler gets executed but i have to do some synchronizations to get it right and maybe there is an easier way for this..
So my question , when i use send without async, is it normal to not hit the handler?
If you are sending synchronously then your completed handler will never fire because the associated event is only triggered for async calls.
In a synchronous call, just put whatever code you would have put in your handler after your call to Send:
client.Send(message);
//TODO: Put your handler code here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With