如何在c#应用程序中设置计时器 [英] how to set timer in c# APPLICATION

查看:91
本文介绍了如何在c#应用程序中设置计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在我的应用程序中的特定日期发送电子邮件.
如何设置计时器?


Hi
i want to send a email on particular date in my application.....

how to set timer for that?


lbldate.Text = datetime mydate.Tostring();

public void emailSend()
   {
       DataTable dtemplogin = new DataTable();
       dtemplogin = _login.SelectEmpLogin();
       DataTable dtptIns = new DataTable();
       dtptIns = _login.selectPatientInsurance();


       Connection.DataSource = ConfigurationManager.AppSettings["DataSource"].ToString();
       Connection.Uid = ConfigurationManager.AppSettings["uid"].ToString();
       Connection.Pwd = ConfigurationManager.AppSettings["pwd"].ToString();
       Connection.Initialcatalog = ConfigurationManager.AppSettings["InitialCatalog"].ToString();

       MailMsg.mailSend();
       MailMsg.CcAddress = string.Empty;
       MailMsg.BccAddress = string.Empty;
       MailMsg.Attachments = null;
       MailMsg.Subject = "insurance Expiry alert message";
       MailMsg.FromAddress = "radha@rediffmail.com";
       MailMsg.ToAddress = txtEmailID.Text;
       MailMsg.Password = "hhahshd";
       MailMsg.MessageBody += "<html>";
       MailMsg.MessageBody += "<head>";
       MailMsg.MessageBody += "<title>Insurance is going To expiry on:</title>";
       MailMsg.MessageBody += "</head>";
       MailMsg.MessageBody += "<body>";
       MailMsg.MessageBody += dtptIns.Rows[1]["F_Name"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[5]["Ins_Name"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[6]["Effective_Date_From"].ToString();
       MailMsg.MessageBody += dtptIns.Rows[7]["Effective_Date_To"].ToString();
       MailMsg.MessageBody += "</body>";
       MailMsg.MessageBody += "</html>";

   }



在标签中,我有我的日期,当emailsend函数要调用时..
为此,如何设置timer



in label i have my date when the emailsend function want to call..
for that how to set timer

推荐答案

1)您的应用程序必须连续运行才能正常工作,即您必须具有Windows服务等.

2)将日期保存到文件或数据库中.

3)创建一个Thread,它每1秒钟休眠一次,并检查日期是否已过,如果是,请执行emailsend方法.
1) Your application must be running continuously for this to work ie you must have a windows service etc.

2) Save your dates to a file or a database.

3) Create a Thread which sleeps every 1 sec and checks if the dates have been passed, if so execute the emailsend method.


这可能对您有帮助,

C#中的计时器 [计时器类 [
It might help you,

Timer in C#[^]

Timer Class[^]

:)


在计时器滴答事件中,检查所需的日期和时间,
如果其(检查值)值为true
然后调用电子邮件发送方法.
In the timer tick event, check the required date and time ,
If its(checking value) value is true
then call the Email send method..


这篇关于如何在c#应用程序中设置计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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