互联网连接后自动发送电子邮件. [英] Send an email automatically when internet connected .

查看:118
本文介绍了互联网连接后自动发送电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好,
我正在使用C#.net在Windows应用程序中进行预订表格.
我在预订按钮点击事件中发送电子邮件.
我的问题是在预订时没有网.一小时后,互联网就来了.我该如何等待呢.

Good Evening,
I am doing Reservation Form in Windows applications using C#.net.
I send an email at reservation button click event.
My problem is at the time of reservation there is no net. after one hour internet is coming. how can i put this in waiting. is there any way to do this.

推荐答案

如果当前没有连接,则应将电子邮件保存到磁盘.也许您应该然后建立一个Windows服务来轮询电子邮件文件夹,然后每当有未送达的邮件时检查是否存在Internet连接.

希望这对您有帮助
You should just save the email to disk if there is currently no connection. Maybe you should then institute a Windows Service that polls the email folder, and then checks if there is an internet connection whenever there is any undelivered mail.

Hope this helps


Wayne是正确的.

但是,当Internet连接时,您还需要触发操作.不幸的是,没有任何东西会通知您.我建议您创建一个Windows服务,以检测您的电子邮件服务器(SMPT服务器或您使用的任何服务器)的可访问性.您可以通过ping它的IP来实现.

因此,您需要在服务中使用单独的线程,并定期对服务器执行ping操作.周期由System.Threading.Thread.Sleep中的某个延迟确定.对于ping,请使用类System.Net.NetworkInformation.Ping.另外,当Internet可用时,您的线程应保持等待状态.为此,请使用类System.Threading.EventWaitHandle.在线程之间共享此类的实例.您的ping线程应在每个周期中调用EventWaitHandle.WaitOne.当您检测到Internet在任何其他线程中突然断开连接(由于通信中的任何异常)时,应在同一实例上调用EventWaitHandle.Set.它将唤醒正在等待的ping线程,并使其开始ping.

—SA
Wayne is right.

However, you also need to trigger the action when Internet got connected. Unfortunately, nothing will give you notification. I suggest you create a Windows Service which detect accessibility of your e-mail server (SMPT server or whatever you use). You can do it by pinging its IP.

For this reason, you need to have a separate thread in your Service with periodically pings your server. The period will be determined by some delay in System.Threading.Thread.Sleep. For pinging, use the class System.Net.NetworkInformation.Ping. Also, you thread should stay in wait state when Internet is available. For this purpose, use the class System.Threading.EventWaitHandle. Share an instance of this class between thread. Your pinging thread should call EventWaitHandle.WaitOne in each cycle. When you detect that Internet was suddenly disconnected (by any exception in communication) in any other thread, you should call EventWaitHandle.Set on the same instance. It will wake-up the waiting pinging thread and let it start pinging.

—SA


这篇关于互联网连接后自动发送电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆