|
Dear All,
Im making a windows service in vs 2008. it has to perform a task once a day at 12:00 AM.
What is the best way to accomplish this? using Timers? or other ways?
Thanks in advance.
|
|
|
|
|
Does it really have to be a windows service if you only need to run it once every day at a certain time? Maybe you could schedule windows to run your program att 12AM instead?
|
|
|
|
|
Hi Calla,
Thanks for response.
It has to be a win service that automatically runs at that time and not throug windows
|
|
|
|
|
Priya Prk wrote: It has to be a win service
Why? What will the task do?
It's probably not the best technique. If it's a homework assignment, then it's OK. But if it's a work assignment then you should take our suggestions and comments to your boss and ask if he agrees with us. A smart boss will see our point, but there could be other concerns you don't know about and haven't presented. For instance, this may be just the first phase of a larger scheduling project.
Priya Prk wrote: not throug windows
It's going to be "through Windows" either way.
P.S.
Priya Prk wrote: that automatically runs at that time
Do you understand that a Windows Service is always running? (Unless you stop it of course.)
|
|
|
|
|
I would use a Windows Scheduled Task; not a Windows Service.
I only use a Windows Service for things that need to happen much more frequently (perhaps up to every ten minutes). Even things that are to happen every hour are better done with a task, in my opinion.
What will the process do?
|
|
|
|
|
I worked with events (cause your service should be able to stop on request) and used a loop like this.
timeToWait = CalcMillisecondsTillMaintainceFromNow();
while(true)
{
if(WaitForEvents(timeToWait) == event fired)
timeToWait = CalcMillisecondsTillMaintainceFromNow();
else
InvokeMaintanceRoutine();
}
Greetings
Covean
|
|
|
|
|
If it has to run only once a day, you don't need a Windows Service because that is not what it was made for . Instead, create a console application that does your work and use Task Scheduler to run your app at 12:00 AM.
|
|
|
|
|
Sorry I voted your answer with 1, cause you are the 3th one who said to use the task planer and he also said it has to be a service!
Greetings
Covean
|
|
|
|
|
May be the OP does not know what he/she wants. That is why I suggested console app + Task schduler will be a better candidate than a Windows Service. Windows Service is NOT designed to act like a task scheduler.
|
|
|
|
|
But you were the third one who said exactly the same! And this even after the OP said it has to be a service!
Greetings
Covean
|
|
|
|
|
The Windows Task Scheduler is a service. Maybe the OP doesn't know that.
|
|
|
|
|
Maybe the OP has known that the Windows Task Scheduler is a service but its simply not available (cause as a result of some security issue they disabled the task planer) on the machine he has to do his maintenance or something else.
Greetings
Covean
|
|
|
|
|
So, from when have you started mind-reading? As technology specialists, our job is not just to give answers, but the best answers, and that is what I am trying to do here. The OP did not mention anywhere that Task Scheduler cannot be used. What I gave is a general idea.
I would suggest that you try to help OP on your own rather than concentrating on others' answers and rating them down (insanely and for imaginary reasons).
|
|
|
|
|
Hi Calla,
Thanks for response.
It has to be a win service that automatically runs at that time and not throug windows
Was the first and only answer from the OP! Read and understand it!
After this and 2 other poster, whose said to use the task planer, you answered exactly the same,
thats the point! Thats why I down voted you. I never had answered to this thread if he hadn't answered
this way! I only offered an alternative like I implemented it in a service years ago (but this service has to do more then just start some scheduled task).
So at last: I never said your answer is wrong, but 3 times the same sh... after the OP queried for some alternatives.
Greetings
Covean
|
|
|
|
|
Covean wrote: It has to be a win service that automatically runs at that time and not throug windows
If you want something that runs automatically at a particular time, then a windows service is probably not the answer because that's not what windows services are for. That's what the Task Scheduler is for. I think the fact that several people have made similar suggestions is an indication that there is a modicum of consensus on the issue. There is nothing in the forum rules that I'm aware of that prevents two people from offering the same advice in response to a question.
And what does it mean to have a Windows service that runs "not through Windows". That seems a trifle confused to me to say the least.
|
|
|
|
|
It seems this guy is on a "thumbs down spree" He seems to be more confused than the OP itself.
|
|
|
|
|
Please read my post before once again, and now find out
who wrote "It has to be a win service that automatically runs at that time and not throug windows".
To the task planer issue. I never said its the wrong way, and yes its also the best way in general case.
But please read my posting before.
Greetings
Covean
|
|
|
|
|
When the OP said "not through windows", it means not through interactive user logon, and AFAIK Task Scheduler is a service that runs even if no user is logged in.
And when the OP says "it has to be win service", it may be based on wrong assumptions.
IMO, you can vote an answer down only when it is wrong or out-of-context or is misleading. Offering alternative ideas is no sin and does not deserve a thumbs down (even if it is, it should be ONLY the OP who should do this).
|
|
|
|
|
Shameel wrote: you can vote an answer down only when it is wrong or out-of-context or is misleading
No, this is a democracy, anyone can vote any way they please.
Shameel wrote: Offering alternative ideas is no sin
Indeed; in fact not offering alternative ideas when they apply could be considered a sin of omission.
|
|
|
|
|
PIEBALDconsult wrote: No, this is a democracy, anyone can vote any way they please.
Why should someone vote down a good answer? Even if someone does, a new comer might think that it is a bad answer based on the rating, and that is one of the purposes why rating systems exist.
|
|
|
|
|
Shameel wrote: Why should someone vote down a good answer?
Alas, there are feuds and rivalries and pettiness.
|
|
|
|
|
PIEBALDconsult wrote: Alas, there are feuds and rivalries and pettiness.
Yes, unfortunately there are. But ideally, they should have no place in a technical forum like this.
|
|
|
|
|
Covean wrote: So at last: I never said your answer is wrong, but 3 times the same sh... after the OP queried for some alternatives.
It might be sh** to you, not to the OP. This is what the OP wrote sometime ago to another post in this thread.
"Dear all,
Thanks a lot for usefull responses.
Im very new in this and i thought that a windows service is the solution for my project.
My application had to import some data from network once a day, save it to our db and export it to some other relations.
Bud i will discuse your suggestions with my coworkers.
Thanks a lot."
It means the OP is ready to explore the idea of using task sheduler.
And do you seriously believe that Windows Service exists to do this kind of work ?
|
|
|
|
|
I want to apologize myself for voting you down.
... every following word is just destructive ...
Greetings
Covean
|
|
|
|
|
So, you now atleast agree that you tried to push her out of the window when most of others tried to show her the elevator
|
|
|
|