Asynchronously sending Emails in C#?

后端 未结 10 1443
礼貌的吻别
礼貌的吻别 2020-11-28 23:43

I\'m developing an application where a user clicks/presses enter on a certain button in a window, the application does some checks and determines whether to send out a coupl

10条回答
  •  不知归路
    2020-11-29 00:11

    Just because this is a little vague...I will be brief...

    There are a lot of ways to do asynchronous or parallel work in c#/.net etc.

    The fastest way to do what you want is to use a background worker thread which will avoid locking up your UI.

    A tip with background worker threads : you cannot directly update the UI from them (thread affinity and Marshalling is just something you learn to deal with...)

    Another thing to consider...if you use the standard System.Net.Mail type stuff to send the emails...be careful how you craft your logic. If you isolate it all in some method and call it over and over, it will likely have to tear down and rebuild the connection to the mail server each time and the latency involved in authentication etc will still slow the whole thing down unnecessarily. Send multiple e-mails through a single open connection to the mail server when possible.

提交回复
热议问题