Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between smtpClient.send() and smtpClient.SendAsync()?

Tags:

smtpclient

I am trying to send mail from localhost..

and on doing this i have got methods from different sites to sending mails..but on doing this i am confused between smtpClient.send() and smtpClient.SendAsync()..

I want to know that How they are different from each other???

Thanks in advance..

like image 966
divya Avatar asked May 30 '11 07:05

divya


People also ask

What is SendAsync c#?

SendAsync(HttpRequestMessage, HttpCompletionOption) Send an HTTP request as an asynchronous operation. SendAsync(HttpRequestMessage, CancellationToken) Send an HTTP request as an asynchronous operation.

Is SMTP synchronous or asynchronous?

From the msdn documentation: "Sends an e-mail message to an SMTP server for delivery. These methods block while the message is being transmitted.". So yes it's synchronous.

What is SmtpClient C#?

Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.


2 Answers

smtpClient.send() will initiate the sending on the main/ui thread and would block.
smtpClient.SendAsync() will pick a thread from the .NET Thread Pool and execute the method on that thread. So your main UI will not hang or block.

Async Method Invocation - http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx

like image 184
Aseem Gautam Avatar answered Oct 17 '22 05:10

Aseem Gautam


SendAsyc - Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. More details : SmtpClient.SendAsync Method

like image 2
Anuraj Avatar answered Oct 17 '22 03:10

Anuraj