这样的Timer怎么使,高分90 这样的Timer怎么使?用一个Timer控件去控制方法“GetPic()”的执行,执行的过程是这样的,每五分钟执行一次,但一共只执行两次,不能一直执行下去这样的方法应该怎么写呢??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 定义全局变量 int i=0;定时器函数里 if(i==2){timer.stop();}else{i++;} 也可以使用局部静态变量static int i using System; using System.Timers;namespace Select{ public class RunTime { private Timer _timer = new Timer(); private int i = 0; public void GetPic(object sender, ElapsedEventArgs e) { if (i != 2) { Console.WriteLine("第" + i.ToString() + "次调用"); i++; } else { _timer.Stop(); Console.WriteLine("停止调用了"); } } public void Run() { _timer.Interval = 5*60*1000; _timer.Elapsed += new ElapsedEventHandler(GetPic); _timer.Start(); } } public class MainClass { static void Main(string[] args) { RunTime runTime = new RunTime(); runTime.Run(); Console.Read(); } }} 窗体移动小技巧,做过的进来。 winform中,客户端连不上sql2000数据库 重新建立一个数据库访问页面,访问没起作用,还是访问原来得库 请教:vs2005winform如何通过变量(存有窗体名称)打开新的窗体?谢谢! 动态生成标题列 问一个有关正则的问题!简单!看有几种写法 关于全局变量的问题 C#访问sybase数据库的问题 初学者一问 滚动新闻是如何实现的 求本段的补完 高分,office word编程操作3问
if(i==2)
{
timer.stop();
}
else
{
i++;
}
using System;
using System.Timers;namespace Select
{
public class RunTime
{
private Timer _timer = new Timer();
private int i = 0; public void GetPic(object sender, ElapsedEventArgs e)
{
if (i != 2)
{
Console.WriteLine("第" + i.ToString() + "次调用");
i++;
}
else
{
_timer.Stop();
Console.WriteLine("停止调用了");
}
} public void Run()
{
_timer.Interval = 5*60*1000;
_timer.Elapsed += new ElapsedEventHandler(GetPic);
_timer.Start();
}
} public class MainClass
{
static void Main(string[] args)
{
RunTime runTime = new RunTime();
runTime.Run();
Console.Read();
}
}
}