System.Threading.Timer的使用,c#中线程的使用,我们使用timer对象创建线程的使用方式
工具/原料
vs2010
方法/步骤
1、第一个timer对象的变量,System.Threading.Timerts;给ts赋值ts=newSystem.Threading.Timer(newTimerCallback(A),B, C,D);A表示要执行的方法,可以带参数也可以不带参数B表示要给这A方法传递的参数,如果A方法不带参数,B可以为空C表示这个方法调用之前等待的时间D表示这个方法多久调用一次
2、示例代码如图所示,我贴出完整代码,给大家参考names圬桦孰礅paceConsoleApplication1{classProgr锾攒揉敫am{staticvoidMain(string[]args){Students=newStudent();Console.Read();}}publicclassStudent{publicStudent(){//定义一个对象System.Threading.Timertimer=newSystem.Threading.Timer(newSystem.Threading.TimerCallback(Say),null,10,600);//这里是以秒计时的}//这里的参数必须是object开头的publicvoidSay(objecta){Console.WriteLine("你好");}}}