1, add to Timer control , This control can display the countdown function
2,Timer Control's Tick Event code :
private void timerDownCount_Tick(object sender, EventArgs e) { string
dateDiff = null; // Get the current time DateTime DateTime1 = DateTime.Now; // The next day 00 spot 00 branch 00 second
DateTime DateTime2 = DateTime.Now.AddDays(1).Date; // How many seconds is the difference int sec =
(int)DateTime2.Subtract(DateTime1).TotalSeconds; if (sec == 0) {
// delay 1 Second execution ( Why delay ? If not delayed , At the moment of restart, the time difference between the two is still the same 0, It will trigger a restart again ) Thread.Sleep(1000);
//-------------- Restart the software start--------------- // Open a new instance
Process.Start(Application.ExecutablePath); // Close the current instance
Process.GetCurrentProcess().Kill(); //-------------- Restart the software end----------------- }
if (sec < 0) { this.timerDownCount.Stop(); } else { // hold 2 Turn it into TimeSpan, Convenient calculation
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); TimeSpan ts2 = new
TimeSpan(DateTime2.Ticks); // Time comparison , Get the difference TimeSpan ts =
ts1.Subtract(ts2).Duration(); // result dateDiff = ts.Hours.ToString() + " hour " +
ts.Minutes.ToString() + " minute " + ts.Seconds.ToString() + " second ";
this.labDownCount.Text = dateDiff; } }
Technology
Daily Recommendation