This article describes the method of WinForm implementing the automatic shutdown of the program without running for a period of time. Share it for your reference. The specific implementation method is as follows:
using System; using ; using ; using ; using ; using ; using ; using ; using ; using .X509Certificates; using ; namespace DemoDataGridView { public partial class Form3 : Form, IMessageFilter { private int m_WaitMinute = 0; MyTimer; public Form3() { InitializeComponent(); MyTimer = new Timer(); = 1000; += new EventHandler(MyTimer_Tick); += new EventHandler(Application_Idle); } void MyTimer_Tick(object sender, EventArgs e) { if (m_WaitMinute < 60) { = true; = 10000; //10 seconds m_WaitMinute += 1; // = 1.0 - (m_WaitMinute / 60.0); } else { = false; } } void Application_Idle(object sender, EventArgs e) { if (m_WaitMinute == 0) { ("D:\\", ()); (); } else { if (m_WaitMinute >= 6) { ("D:\\", ()); (); } } } public bool PreFilterMessage(ref Message m) { if (m_WaitMinute != 0) { m_WaitMinute = 0; = false; return true; } return false; } } }
I hope this article will be helpful to everyone's C# programming.