积极答复者
some problem about System.Net.Mail

问题
-
SmtpClient smtp = new SmtpClient(); //实例化一个SmtpClient
MailMessage mm = new MailMessage();
//邮件发送//leave out the other set
smtp.Timeout = 60*1000;//超时
smtp.Send(mm);mm.Dispose();
smtp.Dispose();I can receive the E-Mail, and the E-mail is correct, but the procedure is blocked. Did anyone have this problem?
- 已编辑 dogn582 2013年10月8日 2:27
答案
-
你好:
的确如此,MSDN关于SmptClient类说明说明会阻止当前进程。
如果你想边发送边做其它东西,尝试:
1)使用异步发送机制SendAsync。
2)自定义一个后台线程,在里边调用send发送,然后自定义一个事件通知主程序已经完成发送。
Click For donating:Free Rice For the poor
For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
For more things to talk about? StackOverFlow is your choice.- 已标记为答案 CaillenModerator 2013年10月21日 5:52
-
个人建议使用 SendAsync 是比较方便的,而且不用单独再开一个线程,增加了复杂性
SendAsync 本身能够完成异步工作,单独调用这个方法是不会出现“卡住”的问题的,如果楼主的程序出现了“卡顿”,请仔细检查其它可能引起此类问题的代码,尤其是如 smtpClient.Send 这种“阻塞”式的同步方法,或者有没有什么 While 这样的循环不小心死循环了。
使用 SendAsync 只需要注册侦听 SmtpClient 提供的事件,当发送完成后就可以收到通知进行下一步的逻辑处理,很简单且有效
不重要的其实最重要
- 已标记为答案 CaillenModerator 2013年10月21日 5:52
全部回复
-
你好:
的确如此,MSDN关于SmptClient类说明说明会阻止当前进程。
如果你想边发送边做其它东西,尝试:
1)使用异步发送机制SendAsync。
2)自定义一个后台线程,在里边调用send发送,然后自定义一个事件通知主程序已经完成发送。
Click For donating:Free Rice For the poor
For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
For more things to talk about? StackOverFlow is your choice.- 已标记为答案 CaillenModerator 2013年10月21日 5:52
-
我还是建议用我上面的方法比较妥当。
Click For donating:Free Rice For the poor
For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
For more things to talk about? StackOverFlow is your choice. -
个人建议使用 SendAsync 是比较方便的,而且不用单独再开一个线程,增加了复杂性
SendAsync 本身能够完成异步工作,单独调用这个方法是不会出现“卡住”的问题的,如果楼主的程序出现了“卡顿”,请仔细检查其它可能引起此类问题的代码,尤其是如 smtpClient.Send 这种“阻塞”式的同步方法,或者有没有什么 While 这样的循环不小心死循环了。
使用 SendAsync 只需要注册侦听 SmtpClient 提供的事件,当发送完成后就可以收到通知进行下一步的逻辑处理,很简单且有效
不重要的其实最重要
- 已标记为答案 CaillenModerator 2013年10月21日 5:52