C# - 在特定时间触发winform app [英] C# - trigger winform app at a specific time

查看:308
本文介绍了C# - 在特定时间触发winform app的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发小型winform应用程序,以便在每天的特定时间向客户发送自动电子邮件。客户将从UI设置时间,因此当系统时间=客户设置的时间时,我的应用程序将发送电子邮件。我添加了一个datetimepicker,客户在其中设置了所需的触发时间。定制日期时间选择器的格式到时间。





  private   void  timer1_Tick( object  sender,EventArgs e)
{
timer1.Enabled = true ;
timer1.Interval = 1000 ;
toolStripTextBox1.Text = DateTime.Now.ToString( dd-MM-yyyy) ;
toolStripTextBox2.Text = DateTime.Now.ToString( h:mm:ss tt );

}





  private   void  Form1_Load( object  sender,EventArgs e)
{

dateTimePicker1.Format = DateTimePickerFormat.Time;
dateTimePicker1.ShowUpDown = true ;
dateTimePicker1.CustomFormat = h:mm:ss tt;
dateTimePicker1.Value = DateTime.Now;
}





我现在很困惑,如果在datetimepicker.value = toolStripTextBox2.Text如何comapre?因为即使我是comapre,也没有错误,但仍然没有发送电子邮件。



我尝试了什么:



if(dateTimePicker1.Value.ToString()== toolStripTextBox2.Text)

{

textBox3.Text =问题解决了;

}

解决方案

文本框的目的是什么?加载时的所有应用程序需求都是从用户获取时间值。然后它将该时间保存为变量,然后可以将其与时钟时间进行比较,以便决定何时发送电子邮件。


我建​​议你使用 Windows任务计划程序 [ ^ ]。

I am developing small winform app to send an automatic email to customer at a specific time everyday.The customer will set the time from the UI, so when the system time = time set by customer, my app will send email. I included a datetimepicker in which customer set his desired trigger time. The customized the format of date time picker to time.


private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;
            toolStripTextBox1.Text = DateTime.Now.ToString("dd-MM-yyyy");
            toolStripTextBox2.Text = DateTime.Now.ToString("h:mm:ss tt");
           
        }



private void Form1_Load(object sender, EventArgs e)
       {

           dateTimePicker1.Format = DateTimePickerFormat.Time;
           dateTimePicker1.ShowUpDown = true;
           dateTimePicker1.CustomFormat = "h:mm:ss tt";
           dateTimePicker1.Value = DateTime.Now;
       }



I am confused now that, how to comapre if datetimepicker.value = toolStripTextBox2.Text? Because even if I comapre, there is no error but still email is not getting sent.

What I have tried:

if (dateTimePicker1.Value.ToString() == toolStripTextBox2.Text)
{
textBox3.Text = "problem solved";
}

解决方案

What is the purpose of the textboxes? All the app needs on load is to get the time value from the user. It then saves that time as a variable, and can then compare that to the clock time, in order to decide when to send the email.


I suggest you to use the Windows Task Scheduler[^] instead.


这篇关于C# - 在特定时间触发winform app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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