WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法
本文實(shí)例講述了WinForm實(shí)現(xiàn)程序一段時(shí)間不運(yùn)行自動(dòng)關(guān)閉的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
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; } } }
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- C# WinForm 判斷程序是否已經(jīng)在運(yùn)行,且只允許運(yùn)行一個(gè)實(shí)例,附源碼
- .Net WInform開(kāi)發(fā)筆記(二)Winform程序運(yùn)行結(jié)構(gòu)圖及TCP協(xié)議在Winform中的應(yīng)用
- ASP.NET也像WinForm程序一樣運(yùn)行的實(shí)現(xiàn)方法
- c# Winform 程序自動(dòng)更新實(shí)現(xiàn)方法
- C#中WinForm程序退出方法技巧總結(jié)
- C# WinForm應(yīng)用程序降低系統(tǒng)內(nèi)存占用方法總結(jié)
- C# WinForm程序完全退出的問(wèn)題解決
- 解讀在C#中winform程序響應(yīng)鍵盤(pán)事件的詳解
- .Net中導(dǎo)出數(shù)據(jù)到Excel(asp.net和winform程序中)
- WinForm防止程序重復(fù)運(yùn)行的方法分析
相關(guān)文章
C#實(shí)現(xiàn)FTP文件下載及超時(shí)控制詳解
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)FTP文件下載及超時(shí)控制的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03C#使用System.Environment獲取電腦的相關(guān)屬性
這篇文章主要為大家詳細(xì)介紹了C#使用System.Environment獲取電腦的相關(guān)屬性,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10unity實(shí)現(xiàn)屏幕上寫(xiě)字效果
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)屏幕上寫(xiě)字效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07C#使用Task實(shí)現(xiàn)執(zhí)行并行任務(wù)的原理的示例詳解
Task是一個(gè)表示異步操作的類(lèi),它提供了一種簡(jiǎn)單、輕量級(jí)的方式來(lái)創(chuàng)建多線程應(yīng)用程序。本文就來(lái)和大家聊聊在C#中如何使用Task執(zhí)行并行任務(wù)吧2023-04-04C#實(shí)現(xiàn)在控制臺(tái)輸入密碼顯示星號(hào)的方法
這篇文章主要介紹了C#實(shí)現(xiàn)在控制臺(tái)輸入密碼顯示星號(hào)的方法,感興趣的小伙伴們可以參考一下2016-04-04C#實(shí)現(xiàn)軟件監(jiān)控外部程序運(yùn)行狀態(tài)的方法
這篇文章主要介紹了C#實(shí)現(xiàn)軟件監(jiān)控外部程序運(yùn)行狀態(tài)的方法,可實(shí)現(xiàn)監(jiān)控另一個(gè)程序的運(yùn)行狀態(tài)及觸發(fā)相應(yīng)事件的功能,是非常實(shí)用的技巧,需要的朋友可以參考下2014-12-12