调度vs2003中的计时器控制,以便在特定时间执行,如凌晨4点或凌晨1点 [英] schedule timer control in vs2003 to execute at specific time like 4 am or 1 am

查看:47
本文介绍了调度vs2003中的计时器控制,以便在特定时间执行,如凌晨4点或凌晨1点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决我的问题







我正在使用windows应用程序发送邮件没有人从我的数据库中获取数据。在这里,我使用定时器控制并将定时器间隔设置为86400000,因此它将每24小时执行一次。一时间开始我以为我完成了我的任务,但现在我想在凌晨4点执行计时器。我如何用我的代码实现这一点,这是我的代码:



Please help me to solve my problem



I am using the windows application to send mail to no of people fetching the data from my database. Here i used timer control and set the timer interval to 86400000 so it will execute every 24 hr . For time begin i thought i am done with my task but now i want to execute the timer at 4 AM . how can i achieve this with my code , Here is my Code :

private void tmrScheduler_Tick(object sender, System.EventArgs e)
        {
            try
            {
                tmrScheduler.Stop();
                tmrScheduler.Interval=86400000;
                //Only for the ASLC Module
                
                SendNotification();
                
                //to send the mails to the respective User regarding the Policy Expiry
                //For only PolicyException Module
                SendPolicyExpiryNotificationMails();
                GetNullandVoidData();
            }
            catch(Exception Ex)
            {
                throw Ex;
            }
            finally{tmrScheduler.Start();}

        }









我在页面中调用此功能负载





请在特定时间EX:上午4点或下午12点等帮助执行此计时器等。







谢谢&问候



Rajesh Yerramsetti





I am call this function in page Load


Please Help in Executing this Timer at Specific time EX: at 4 AM or 12 pm etc.



Thanks & Regards

Rajesh Yerramsetti

推荐答案

首先,将计时器设置为24小时间隔不是好主意 - 它没有给出任何真正的灵活性。我会将它设置为一个较小的间隔(例如一分钟)并使用计数器来判断一段时间已经过去,或者存储一段时间的值并检查它是否在过去。如果是这样的话,是时候做计时器所做的任何动作。



但是我不会从计时器那样做任务 - 我将使用 Windows任务计划程序 [ ^ ]在指定的时间运行我的应用程序......
First off, setting a timer to a 24 hour interval is not a brilliant idea - it doesn''t give any real flexibility. I would set it to a smaller interval (a minute for example) and use a counter to tell when a period has elapsed instead, or store a time-to-do-it value and check if that is in the past. If so, it''s time to do whatever action the timer is there for.

But I wouldn''t do a task like that from a Timer - I would use the Windows Task Scheduler[^] to run my app at the specified time instead...


这篇关于调度vs2003中的计时器控制,以便在特定时间执行,如凌晨4点或凌晨1点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆