📄 sample56.cs
字号:
namespace apiBook
{
using System;
using System.Threading;
class App
{
static Timer test;
static int count=0;
public static void Main()
{
TimerCallback timerCallback = new TimerCallback(DoPrint);
Timer timer = new Timer(timerCallback, test,500, 500);
test=timer;
Console.ReadLine();
}
static void DoPrint(Object obj)
{
count++;
Console.WriteLine(DateTime.Now.ToString()+" 现在执行的是第"+ count+"线程。");
if(count == 5)
{
Console.WriteLine("现在将间隔的时间延长一倍:");
test.Change(10000,1000);
//使用Change方法修改时间间隔
}
if(count == 10)
{
Console.WriteLine("释放当前实例使用的所有资源并在处置完计时器时发出信号");
test.Dispose();
//使用Dispose方法释放资源
test = null;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -