Greetings.

There is a question about opening a window at a given time. For example, at 12:00:05 you need to open a form with a reminder to feed the cat.

In principle, I realized that I need to set the timer, in which it will work, but I don’t really understand what to do next. How to show the timer that it should work not with ticks, but with a specified time?

If possible, with an example.

Thank you in advance.

    2 answers 2

    And to read the documentation?

    using System.Threading; var timer = new Timer( _ => OpenWindow, null, new DateTime(2014, 5, 18, 12, 0, 5) - DateTime.Now, TimeSpan.FromMilliseconds(-1)); void OpenWindow() { // marshal to UI thread } 

    And no polling, God forgive me.

    • 2014, 5, 18, this is the date. Without it, I will not go, as I understand it. And evriday? get out like this <pre> <code> int hr = 16; int min = 49; int sec = 00; if ((hr> = System.DateTime.Now.Hour) && (min> = System.DateTime.Now.Minute) && (sec> = System.DateTime.Now.Second)) {MessageBox.Show ("Alarm, Cat hungry"); } System.Threading.Thread.Sleep (10); </ code> </ pre> - VaLenOK007
    • @ VaLenOK007: Well, take the values ​​of the year, month and day from DateTime.Now . - VladD
    • Well, thanks for the help) - VaLenOK007
    • @ VaLenOK007: please! - VladD

    It is necessary to receive the current time every second, and if it is equal to some value, show the window.

    • It's clear. It is not clear to me how to make the timer compare. The fact that you need to set the hours and minutes into variables is understandable, but I don’t really understand how to implement it - VaLenOK007