14

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..

zoul
  • 102,279
  • 44
  • 260
  • 354
divya
  • 405
  • 2
  • 6
  • 18

2 Answers2

14

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

A G
  • 21,087
  • 11
  • 87
  • 112
  • But can you tell me that which one should be used?? – divya May 30 '11 at 07:23
  • 1
    If the sending involves attachments and takes a bit of time, go with Async. But you will have to spend some time reading how Asynchronous operations work in .NET. MSDN has already given an example for smtpClient.SendAsync, you can go ahead and use it. – A G May 30 '11 at 07:27
  • 4
    @AseemGautam SendAsync() doesn't use the ThreadPool's Thread it just uses the Asynchronous Operation Manager – Rushi Soni Oct 30 '13 at 16:12
  • This explains SendAsync() quite well: https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient.sendasync?view=netcore-3.1#definition – Sam Sep 15 '20 at 22:48
2

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

Anuraj
  • 18,859
  • 7
  • 53
  • 79