473,657 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8249
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.N ow".

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_DO T_cuhk_DOT_edu_ DOT_hk
Jan 12 '07 #3
On Thu, 11 Jan 2007 14:58:00 -0800, Peter Bromberg [C# MVP]
<pb*******@yaho o.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.Da y)
{
CurrentDay = DateTime.Now.Da y;
//..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
1881
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 HAS THE SCROLLBAR (does not if the right side does not have the scrollbar on). Also, if you move around each "this is a test" line, the onmouseout event fires. How odd? Fortunately, I can have logic to handle this. The big problem is why...
9
3999
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 records that are being edited, the event does fire. Has this (previous) behaviour been changed by Microsoft?
5
6799
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 way is using javascript - does anybody have a sample for this ? Thanks
2
3883
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 response.write on its click handler but it won't fire either telling me no button click events will fire. But my calendar control on the same page does fire. In the debugger I put a break point in the calendar event and the button
2
1506
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 the last page 2) fire select 3) fire delete 4) what is the last row in the last page
6
2203
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
10364
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 PostBack. How can I then fire the click event of Button2 during the same PostBack? I know this seems like a totally bad situation I'm creating out of naiveity. But please indulge. It would save me from having to provide a lengthy explanation for...
4
5293
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 button fire even though nothing is subscribed to listen to the event. The answer is NO in a traditional Publisher/Subscriber design pattern (at least I think it is). I have stated that if nothing is subscribed, then the event never gets
19
4749
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 DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6163
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.