Time-based shutdown of small software

Source: Internet
Author: User

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/");
}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.