c#中System.Threading.Timer 线程的使用

 时间:2026-02-14 17:04:16

1、第一个timer对象的变量, System.Threading.Timer ts;  

给ts赋值

ts =  new System.Threading.Timer(new TimerCallback(A), B, C, D);

A表示要执行的方法,可以带参数也可以不带参数

B表示要给这A方法传递的参数,如果A方法不带参数,B可以为空

C表示这个方法调用之前等待的时间

D表示这个方法多久调用一次

2、示例代码如图所示,我贴出完整代码,给大家参考

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            Student s = new Student();

            Console.Read();

           

        }

    }

    public class Student

    {

        public Student()

        {

            //定义一个对象

            System.Threading.Timer timer = new System.Threading.Timer(

                new System.Threading.TimerCallback(Say), null,

                10, 600);//这里是以秒计时的

        }

        //这里的参数必须是object开头的

        public void Say(object a )

        {

            Console.WriteLine("你好");

        }

    }

}

c#中System.Threading.Timer 线程的使用

  • 后台svchost.exe把物理内存占满了怎么办?
  • Autodesk Inventor2019注册机安装教程
  • 神州专车怎么样指派司机和车辆
  • 阴阳师百鬼票怎样来的快
  • 太吾绘卷如何快速赚银钱
  • 热门搜索
    压力mpa是什么意思 一本正经是什么意思 什么牌子的维生素c好 风信子什么时候开花 坦然什么意思 婆婆丁是什么 神态自若的意思是什么 酸辣椒的腌制方法 range是什么意思 黄页是什么