I have a program with a button but I'd like to trigger that after a specific time. How do I do that? I have tried this code but there is no ElapsedEventArgs
in my timer event.
static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (DateTime.Now.Hour == 1 && DateTime.Now.Minute == 0)
{
// do whatever
}
}
I also tried:
if (System.DateTime.Now.Minute == 35)
{
btn_readAttLog.PerformClick();
button2.PerformClick();
}
but it's not working. Is there any way to do this?
Here's the better way of working with DateTime.Now
.
var d = DateTime.Now;
if (d.Hour == 3 && d.Minute == 46)
{
Console.WriteLine("good");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.