关于定时器的问题 我遇到一个问题,我想在每天下午2点运行函数send(),我创建了控件Timer1,但不知道怎么写代码,能指导我下怎么写代码吗?还有就是另外一个函数get()要每过十天运行一次,我创建了空间Timer2,应该如何写代码?谢谢了:) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个应该可以做成Windows Service的,我也不太会。提供一个笨方法:using System;using System.Timers;using System.Windows.Form;namespace DetailsTest{ public class Test { static System.Timers.Timer t1 = new System.Timers.Timer(); static Thread thread; public static void Main(string[] args) { Th(); Form f = new Form(); //这里为了让程序一直停在这,显示了一个Form f.ShowDialog(); //如果本身是WinForm的就这个必要了 } public static void Th() { t1.Interval = 1000; //一秒钟一次 t1.Elapsed += new ElapsedEventHandler(RestartTimer); t1.Enabled = true; } public static void RestartTimer(object sender, ElapsedEventArgs e) { DateTime dt = DateTime.Now; if (dt.Hour == 14) //判断当前时间是否为14点 { t1.Elapsed -= new ElapsedEventHandler(RestartTimer); t1.Elapsed += new ElapsedEventHandler(Every24Hours); t1.Interval = 3600 * 1000 * 24; //改成24小时一次 t1.Enabled = true; } } public static void Every24Hours(object sender, ElapsedEventArgs e) { Console.WriteLine(DateTime.Now.ToString("hh-mm-ss")); send(); } public static void send() { } }} |ZYCWPF| 在MVVM中声明了一个事件,那如何用代码去调用这个事件 有示例代码 谢谢 如何实现优先队列? C#listbox问题 treeet[] getChildren(); 是啥意思? 100分求 ANSI转UNICODE····急啊···望高手帮忙····在线等啊···顶者有分 数据显示在textBox中 问一个关于钩子的问题 问个C#该做什么领域的问题 什么是正则表达式! 如果客户用xp home的话,运行NET编的软件,除了安装Framework net2.0 还要装些什么 动态添加控件后无法响应其定义的事件 c#2.0里面如何读取Resources.resx里面的内容?
提供一个笨方法:
using System;
using System.Timers;
using System.Windows.Form;namespace DetailsTest
{
public class Test
{
static System.Timers.Timer t1 = new System.Timers.Timer();
static Thread thread;
public static void Main(string[] args)
{
Th();
Form f = new Form(); //这里为了让程序一直停在这,显示了一个Form
f.ShowDialog(); //如果本身是WinForm的就这个必要了
}
public static void Th()
{
t1.Interval = 1000; //一秒钟一次
t1.Elapsed += new ElapsedEventHandler(RestartTimer);
t1.Enabled = true;
} public static void RestartTimer(object sender, ElapsedEventArgs e)
{
DateTime dt = DateTime.Now;
if (dt.Hour == 14) //判断当前时间是否为14点
{
t1.Elapsed -= new ElapsedEventHandler(RestartTimer);
t1.Elapsed += new ElapsedEventHandler(Every24Hours);
t1.Interval = 3600 * 1000 * 24; //改成24小时一次
t1.Enabled = true;
}
} public static void Every24Hours(object sender, ElapsedEventArgs e)
{
Console.WriteLine(DateTime.Now.ToString("hh-mm-ss"));
send();
}
public static void send()
{
}
}
}