zoukankan      html  css  js  c++  java
  • C# 计时器和计数

    定义:
    System.Threading.Timer timer;
    int count;
    TextBox textBox1;

    创建计时器和每秒要执行的方法:
    timer = new System.Threading.Timer(st =>
    {
    ++count;
    textBox1.AppendText("计数:" + count.ToString() + " ");
    if (count == 100)
    timer.Change(Timeout.Infinite, Timeout.Infinite);
    },null, Timeout.Infinite, Timeout.Infinite);
    或(callback是执行函数):
    timer = new System.Threading.Timer(callback,null, 1000, 500); (毫秒)
    private void Callback( Object state )
    {
    // 执行操作,执行完归零计时器,回调callback,如此循环
    timer .Change( 1000, 500);
    }

    以上函数后两个参数的意义:
    Timer(TimerCallback callback, object state , uint duetime , uint period)
    duetime:回调首次被调用之前的时间,如果被设置为Timeout.Infinite则会停止计时
    period:两次回调之间的时间间隔,如果被设置为Timeout.Infinite则回调只调用一次

    启动:
    textBox1.AppendText("开始 ");
    count = 0;
    timer.Change(0, 1000);

    暂停:
    timer.Change(Timeout.Infinite, Timeout.Infinite);

    继续:
    timer.Change(0, 1000);

    停止:
    timer.Change(Timeout.Infinite, Timeout.Infinite);
    count = 0;

  • 相关阅读:
    webpack学习(一)—— 入门
    AMD 规范
    CommonJS 规范
    webpack 故障处理
    webpack 开发环境
    webpack 插件
    webpack 配置文件
    webpack 使用
    webpack Loader
    webpack常用的插件安装命令
  • 原文地址:https://www.cnblogs.com/wa502/p/12187213.html
Copyright © 2011-2022 走看看