C#中定时器问题!!!我想设计一个定时器,精确到天,时分秒不考虑,用户通过dateTimePicker设定提醒日期,比如:现在是时间是2010-8-26
用户选择的提醒日期是2010-8-30这一天,等到系统时间到达这一天时,然后弹出消息窗体!请问代码怎么写?请尽量详细点,我是初学的,谢谢!我知道定时秒的,代码如下:
private void help_Load(object sender, EventArgs e)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(theout);
aTimer.Interval =1000;//设置初始时间间隔为1秒!!!
aTimer.AutoReset = true;
aTimer.Enabled = true;
} public void theout(object source, System.Timers.ElapsedEventArgs e)
{
ArrayList AutoTask = new ArrayList();
AutoTask.Add("8:30:00");
AutoTask.Add("9:30:00");
AutoTask.Add("10:30:00");
AutoTask.Add("11:30:00");
for (int k = 0; k < 4; k++)
{
if (DateTime.Now.ToLongTimeString().Equals(AutoTask[k]))
{
MessageBox.Show("现在时间是" + AutoTask[k]);
}
}
} 这样定时秒钟能成功,但我现在想以天数为单位,定时到某一天之后弹出消息窗体,代码怎么写?
用户选择的提醒日期是2010-8-30这一天,等到系统时间到达这一天时,然后弹出消息窗体!请问代码怎么写?请尽量详细点,我是初学的,谢谢!我知道定时秒的,代码如下:
private void help_Load(object sender, EventArgs e)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(theout);
aTimer.Interval =1000;//设置初始时间间隔为1秒!!!
aTimer.AutoReset = true;
aTimer.Enabled = true;
} public void theout(object source, System.Timers.ElapsedEventArgs e)
{
ArrayList AutoTask = new ArrayList();
AutoTask.Add("8:30:00");
AutoTask.Add("9:30:00");
AutoTask.Add("10:30:00");
AutoTask.Add("11:30:00");
for (int k = 0; k < 4; k++)
{
if (DateTime.Now.ToLongTimeString().Equals(AutoTask[k]))
{
MessageBox.Show("现在时间是" + AutoTask[k]);
}
}
} 这样定时秒钟能成功,但我现在想以天数为单位,定时到某一天之后弹出消息窗体,代码怎么写?
解决方案 »
- vs2008下c#中如何开大数组
- 这是什么意思?
- ~~~~~~~~~~~~~~~~c#和数据库连不上了?
- 请教:如何将XML字符串直接读入dataset,而不从文件读取
- 堆与堆栈的区别是什么?
- 菜鸟向各位高手请教,关于用socket连接发送任何文件的问题
- 求教关于批量调用控件方法问题。
- .net+oracle: Specified argument was out of the range of valid values
- c#中 如何实现日历的选取
- SQL数据库精度
- 请教Lambda表达式num => num如何用ParameterExpression的方式表示?
- 类型"xx"中不存在"BooksDataSet"
if(DateTime.now.ToString().Subsring(0,...)==你想要的时间(精确到天))
MessageBox.Show(.....);
1楼是说这样吗?
aTimer.Interval =1000*24*60*60;//设置初始时间间隔为1天!!!
3楼,你还,我根据你的提示,在里面的代码如下,
if (DateTime.Now.ToString().Substring(0, Arry[j].Length) == Arry[j])我是把“我想要的时间”放在string 数组里的,即Arry数组里,然后用的。
可出不来效果啊!
是什么情况?能否剖析下?