启动以后自动将一个Timer激活,在Timer时间到的时候触发this.Close
public partial class Form1 : Form
    {
        Timer 我的计时器 = new Timer();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            我的计时器.Interval = 10000;//设置时间为10秒
            我的计时器.Tick += new EventHandler(我的计时器_Tick);
            我的计时器.Start();//窗体加载时这个计时器自动启动
        }
        //计时器计时事件
        void 我的计时器_Tick(object sender, EventArgs e)
        {
            this.Close();//时间到了以后就触发窗体关闭事件了
        }
}

 

用stopwatch可以来计算程序模块运行的时间..

using System.Diagnostics;

Stopwatch tm = new Stopwatch();
tm.Start();

某个模块...

tm.Stop();

MessageBox.Show(tm.Elapsed.Milliseconds.ToString(), "training done");

相关文章:

  • 2021-07-31
  • 2021-12-02
  • 2021-08-04
猜你喜欢
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-09-09
  • 2021-05-15
相关资源
相似解决方案