WinForm实现程序一段时间不运行自动关闭的方法
程序员文章站
2022-10-15 10:18:05
本文实例讲述了winform实现程序一段时间不运行自动关闭的方法。分享给大家供大家参考。具体实现方法如下:
using system;
using system...
本文实例讲述了winform实现程序一段时间不运行自动关闭的方法。分享给大家供大家参考。具体实现方法如下:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.text; using system.windows.forms; using system.net; using system.io; using system.security.cryptography.x509certificates; using system.net.security; namespace demodatagridview { public partial class form3 : form, imessagefilter { private int m_waitminute = 0; system.windows.forms.timer mytimer; public form3() { initializecomponent(); mytimer = new timer(); mytimer.interval = 1000; mytimer.tick += new eventhandler(mytimer_tick); application.idle += new eventhandler(application_idle); } void mytimer_tick(object sender, eventargs e) { if (m_waitminute < 60) { mytimer.enabled = true; mytimer.interval = 10000; //10秒 m_waitminute += 1; // this.opacity = 1.0 - convert.todouble(m_waitminute / 60.0); } else { mytimer.enabled = false; } } void application_idle(object sender, eventargs e) { if (m_waitminute == 0) { system.io.file.writealltext("d:\\1.txt", datetime.now.tostring()); mytimer.start(); } else { if (m_waitminute >= 6) { system.io.file.writealltext("d:\\2.txt", datetime.now.tostring()); this.close(); } } } public bool prefiltermessage(ref message m) { if (m_waitminute != 0) { m_waitminute = 0; mytimer.enabled = false; return true; } return false; } } }
希望本文所述对大家的c#程序设计有所帮助。