473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

fire an event at midnight

Jac

Hey,

I have a windows service and when the day change (so at midnight) I want
fire an event so I can execute some code.

Do someone has an idea to do that?

I don't see directly a solution with a timer and an interval. Because
the first time then interval can not be 24hours? Is there something
easier?

thanks
jac
*** Sent via Developersdex http://www.developersdex.com ***
Jan 11 '07 #1
5 8214
Unless you have "other things" going on, it seems like overkill to have a
Windows Service just to take up resources in order to fire one "event" at
midnight.

How about if you just write yourself a console Executable that does your
"thing" and set it up with Task Scheduler to run every day at midnight?
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Jac" wrote:
>
Hey,

I have a windows service and when the day change (so at midnight) I want
fire an event so I can execute some code.

Do someone has an idea to do that?

I don't see directly a solution with a timer and an interval. Because
the first time then interval can not be 24hours? Is there something
easier?

thanks
jac
*** Sent via Developersdex http://www.developersdex.com ***
Jan 11 '07 #2
Jac wrote:
Hey,

I have a windows service and when the day change (so at midnight) I want
fire an event so I can execute some code.

Do someone has an idea to do that?

I don't see directly a solution with a timer and an interval. Because
the first time then interval can not be 24hours? Is there something
easier?

thanks
jac
*** Sent via Developersdex http://www.developersdex.com ***
One method but not so accuracy.

Using a timer with interval 1 minute (or period you select, e.g. 30sec,
15 sec, dependent on how accuracy you want).

Record the current time in every timer event by "DateTime.Now".

Compare the time in currnet timer event and previous timer event. If the
"Day" in the time has changed, execute the code you want.
--
Jacky Kwok
jacky@alumni_DOT_cuhk_DOT_edu_DOT_hk
Jan 12 '07 #3
On Thu, 11 Jan 2007 14:58:00 -0800, Peter Bromberg [C# MVP]
<pb*******@yahoo.yabbadabbadoo.comwrote:
>Unless you have "other things" going on, it seems like overkill to have a
Windows Service just to take up resources in order to fire one "event" at
midnight.

How about if you just write yourself a console Executable that does your
"thing" and set it up with Task Scheduler to run every day at midnight?
Peter
Agree 100%
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Jan 12 '07 #4
Jac


Yes, You right but there is more in my program than that. It polls
constantly a database, but when it is week-end I want the interval for
polling mut be bigger, when it is monday then the interval must be
smaller. Therefore I need to now when the day changes.
But I already found a solution :
When the timer for polling elapse I will check date and then I can
change the interval.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Jan 12 '07 #5
You could for example have the following code (NOTE: Not working, just off
the top of my head)

while(true)
{
If(CurrentDay != DateTime.Now.Day)
{
CurrentDay = DateTime.Now.Day;
//..Fire you code/Event here
}
}

Once again, this is unused untested and very resource hungry due to the fact
of the while loop.

However, I do believe that a safer option would be to use the Task scheduler
included with Windows, as this is a more proven and well tested component.

It could be worth having a read of:
http://blogs.msdn.com/dditweb/archiv...0_-Part-I.aspx

http://www.codeproject.com/csharp/TSNewLib.asp

You could make the Windows Task Scheduler execute a application (unsure if
it can run DLL’s, however you could make a exe to use your DLL) every X time
during the day and also build in the ability to self modify its own schedule
based on what day it is.

Disclaimer: Any source code is posted without warranty or grantee and should
be used at your own risk.
Jan 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kevin Ly | last post by:
Consider the test case below. The onmouseout event does NOT fire when my mouse/cusor is moved off the left side of the browser. It does if it is moved off the top, bottom, and the right side that...
9
by: HJ | last post by:
Hi all, I notice that the Form_Dirty event does not fire in Access 2002 (SP-1) when the first character is typed into a new record. In previous versions of Access it does fire. For existing...
5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
2
by: Sam Miller | last post by:
Hi, I have a button event that won't fire. I left it on Friday and it worked fine. I came back in on Monday and it won't fire. I tried putting another button and just putting a...
2
by: Ofer | last post by:
I finally learned that DataGrid1.EditItemIndex = {row I want} -1 DataGrid1.DataBind() will make that row get to edit mode. I am stiil looking for ways to programticaly do other things: 1) show...
6
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
5
by: Verde | last post by:
This is admittedly an apparently odd request... but please indulge me if you don't mind: Suppose I have two <asp:Button.../> on a page (Button1 and Button2). User clicks Button1 and triggers a...
4
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.