使用Timer:http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx
有代码否
@拖鞋王子:
public class Class1 {
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
static int alarmCounter = 1;
static bool exitFlag = false;
// This is the method to run when the timer is raised.
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
myTimer.Stop();
// Displays a message box asking whether to continue running the timer.
if(MessageBox.Show("Continue running?", "Count is: " + alarmCounter,
MessageBoxButtons.YesNo) == DialogResult.Yes) {
// Restarts the timer and increments the counter.
alarmCounter +=1;
myTimer.Enabled = true;
}
else {
// Stops the timer.
exitFlag = true;
}
}
public static int Main() {
/* Adds the event and the event handler for the method that will
process the timer event to the timer. */
myTimer.Tick += new EventHandler(TimerEventProcessor);
// Sets the timer interval to 5 seconds.
myTimer.Interval = 5000;
myTimer.Start();
// Runs the timer, and raises the event.
while(exitFlag == false) {
// Processes all the events in the queue.
Application.DoEvents();
}
return 0;
}
}
@Greatest: 不是每隔多少时间执行,而且指定时间执行
@拖鞋王子:
private static void TimerEventProcessor(Object myObject,
EventArgs myEventArgs) {
if (now == 6:00)
{
//.....
}
}
@Greatest: 那只能每隔一秒判断一次了
给你个思路把,winfrom:用Timer控件,每隔一定的时间去获取当前系统时间,然后判断离12点还剩多少时间,比如5分,就开始每秒去判断,到了12点就开始执行你写的方法(),建议,做一个按钮来停止Timer控件的执行,总不能让Timer一直跑下去啊。
B/S:可以用JavaScript,运行网页就开始判断时间,然后判断是否==12:00。
总结:最好根据客户的使用习惯来写执行代码。
嗯 只能用timer每秒执行了
新建windows 任务,每天指定时间启动winform程序 窗体加载的时候执行,执行完退出