timer每次循环都会执行TIck事件,Tick可以看做一般的函数,只不过是另开了一个线程执行的罢了。
你的需求其实就是计数。那么在类里面定义一个计数器即可。
public class MyClass
{
private int _count = 0;
private Timer myTimer = new Timer();
//....调用你的timer start stop 什么的
myTimer.Tick += myTimer_TIck(e,sender);
private void myTimer_TIck() //这个函数是你timer每次执行的TIck函数
{
_count ++;
}
}
if(_times>2)
{
fun();
timer.stop();
}