using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AddRoomTimer timer = new AddRoomTimer();
while (true)
{
if (AddRoomTimer.COUNT > 0)
{
Console.WriteLine(string.Format("第{0}次调用", 101 - AddRoomTimer.COUNT));
AddRoomTimer.COUNT--;
}
}
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
public class AddRoomTimer
{
//静态计数器变量
public static int COUNT = 0;
public static System.Threading.Timer timer;
static AddRoomTimer()
{
//多线程定时器, 每隔 10000毫秒调用一次被委托的方法 TimerCallBack
timer = new System.Threading.Timer(TimerCallBack, null, 0, 10000);
}
private static void TimerCallBack(object obj)
{
//打印一次时间, 测试用
Console.WriteLine(DateTime.Now.ToString());
//计数器变量重置
COUNT = 100;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AddRoomTimer timer = new AddRoomTimer();
while (true)
{
if (AddRoomTimer.COUNT > 0)
{
Console.WriteLine(string.Format("第{0}次调用", 101 - AddRoomTimer.COUNT));
AddRoomTimer.COUNT--;
}
}
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
//System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
public class AddRoomTimer
{
//静态计数器变量
public static int COUNT = 0;
public static System.Threading.Timer timer;
//静态构造, 最多运行一次
static AddRoomTimer()
{
//多线程定时器, 每隔 10000毫秒调用一次被委托的方法 TimerCallBack
timer = new System.Threading.Timer(TimerCallBack, null, 0, 10000);
}
private static void TimerCallBack(object obj)
{
//打印一次时间, 测试用
Console.WriteLine(DateTime.Now.ToString());
//计数器变量重置
COUNT = 100;
}
}
}