我很菜,请解释详细点,注明要引用那些命名空间,这个要写在哪个地方(程序入口里还是外面哪里)我找的这个行吗?我把它写在程序入口里了using System.Timers;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices; System.Timers.Timer aTimer = new System.Timers.Timer(600000);
aTimer.AutoReset = true;
aTimer.Enabled = true;
aTimer.Start();
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices; System.Timers.Timer aTimer = new System.Timers.Timer(600000);
aTimer.AutoReset = true;
aTimer.Enabled = true;
aTimer.Start();
System.Timers.Timer t =
new System.Timers.Timer(10000);
//实例化Timer类,设置间隔时间为10000毫秒;
t.Elapsed +=
new System.Timers.ElapsedEventHandler(theout);
//到达时间的时候执行事件;
t.AutoReset = true;
//设置是执行一次(false)还是一直执行(true);
t.Enabled = true;
//是否执行System.Timers.Timer.Elapsed事件;
public void theout(
object source,
System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("OK!");
}
object source,
System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("OK!");
}
----这个的作用是什么?怎么看着和上段像没关联
还有都写在入口里会出错,把上段写入口里,下段放入口外?
{
Timer timer1 = new Timer();
timer1.Interval = 3000;
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
} void timer1_Tick(object sender, EventArgs e)
{
// 这里处理定时需要执行的内容
}
还有windows 任务
using System.Collections.Generic;
using System.Text;
using System.Timers;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;namespace _0fenzhong
{
class Program
{
static void Main(string[] args)
{
System.Timers.Timer t = new System.Timers.Timer(5000); //实例化Timer类,设置间隔时间为?毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); //到达时间的时候执行事件;
t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
t.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件;
}
public void theout(object source,System.Timers.ElapsedEventArgs e)
{
Console.WriteLine("OK!");
}
}
}