I always listen to music and go to bed these nights, but I can't drive my computer for one night. I just want to download a timed shutdown.
I did not find my favorite one, so I wrote a Timed Shutdown for playing.
Simple functions and good use of your own. Haha
The main code is as follows:
// The Shutdown program calls cmd.exe and transmits parameters.
Process. Start ("cmd.exe", "/c shutdown/s/t 10 ");
// Calculate the time interval TimeSpan
TimeSpan ts = new TimeSpan (dtpSetTime. Value. Ticks-DateTime. Now. Ticks );
The complete code is as follows:
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;
Using System. Diagnostics;
Namespace Timed Shutdown
{
Public partial class frmMain: Form
{
Public frmMain ()
{
InitializeComponent ();
}
Private void timereffectick (object sender, EventArgs e)
{
// Time is up
If (dtpSetTime. Value. ToString () = DateTime. Now. ToString ())
{
// Shutdown
Process. Start ("cmd.exe", "/c shutdown/s/t 10 ");
Timer1.Enabled = false;
//
DtpSetTime. Enabled = true;
BtnDo. Text = "Start of Countdown ";
BtnExitClose. Enabled = true;
Return;
}
TimeSpan ts = new TimeSpan (dtpSetTime. Value. Ticks-DateTime. Now. Ticks );
LblInfo. Text = "remaining after shutdown" + (int) ts. TotalHours + "Hour" + ts. Minutes + "Minute" + ts. Seconds + "second ";
}
Private void Form1_Load (object sender, EventArgs e)
{
DtpSetTime. Value = DateTime. Now;
}
Private void btnStart_Click (object sender, EventArgs e)
{
// Whether the time setting permits
If (dtpSetTime. Value. Ticks <= DateTime. Now. Ticks)
{
Timer1.Enabled = false;
MessageBox. Show ("It cannot be set earlier than now! Time cannot be reversed! ");
Return;
}
If (! Timer1.Enabled)
{
Timer1.Enabled = true;
DtpSetTime. Enabled = false;
BtnDo. Text = "click to stop countdown ";
}
Else
{
Timer1.Enabled = false;
DtpSetTime. Enabled = true;
BtnDo. Text = "Start of Countdown ";
}
}
Private void btnExitClose_Click (object sender, EventArgs e)
{
Process. Start ("cmd.exe", "/c shutdown/");
}
}
}