Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrent use of System.Net.Mail.SendAsync?

I want to use System.Net.Mail.SendAync in an ASP.NET MVC2 application. I see that it throws an InvalidOperationException if there is already a SendAsync call in progress. Does this mean only one SendAsync is allowed per host, or per thread? For example, if I simultaneously have 2 web users from 2 different remote hosts, can each use SendAsync at the same time?

like image 360
royco Avatar asked Dec 21 '25 07:12

royco


1 Answers

One instance of SmtpClient can only run one asynchronous call at a time. You have to create several clients if you want to run several asynchronous calls.

As different threads have their own instance of SmtpClient, they don't collide.

like image 156
Guffa Avatar answered Dec 24 '25 05:12

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!