Timer to close the application

前端 未结 7 1808
离开以前
离开以前 2021-01-12 02:40

How to make a timer which forces the application to close at a specified time in C#? I have something like this:

void  myTimer_Elapsed(object sender, System.         


        
相关标签:
7条回答
  • 2021-01-12 03:17

    Set up your timer to check every second like now, but swap the contents with:

    void  myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
      if (DateTime.Now.Hour == 23)
        this.Close();
    }
    

    This will make sure that when the timer run and the clock is 23:xx, then the application will shut down.

    0 讨论(0)
提交回复
热议问题