I have seen a lot of posts to configure a windows service for daily/weekly etc schedules, but if I want a schedule that is not uniform, how do I manage that from a windows-service perspective? I have an app that I want to run at particular times. Running it at a uniform schedule wouldn't do me any good and just waste resources. Can I configure it by using some XML file, or windows service configuration?
You have three options.
Take a look at Quartz.net
Use Windows scheduler. Just have a different "schedule" for each date/time you need the app to run.
Write your own.
Here's one way to do it that is something of a hybrid approach:
Create a text file that has the dates and times you want the program to run. For example, it might contain:
2011-03-01
0100
0312
0815
0945
1340
2011-03-02
0220
...
Then, write your program that does whatever task it needs to do, and the last thing it does before exiting is read the file, find the next time that it needs to run, and schedules itself (by issuing an AT command, by calling schtasks.exe, or by calling the equivalent Task Scheduler API functions).
The Task Scheduler API is not for the timid. I would suggest looking into a wrapper. A search for "windows task scheduler C#" returns several.
Related
I am trying to develop an application that will scan a website, get data from the website and save that data into database 3x per day at given hour that can be set in xml configuration file.
As an addition group of users can trigger the start of the application manually max few times per day.
I am looking for pros and cons of using a windows service for this solution or should I set a 3 scheduled tasks that will run the console application?
If I will decide to use a windows service then what is the best way to trigger a manual start of the service while the service is already running? The group of users will have some kind of web interface to trigger manual start.
This could be easily done using a scheduled task. I would just set a 3x scheduled tasks that will run the application at given time and the group of users could just start the .exe file from the web interface. However how to only allow the user to run a manual trigger only if application is not already running?
Since the UI is ultimately in web, and thus the service itself won't need any UI, I would go with Windows service which can be triggered to start by the user through web or automatically as the time comes (by its internal code).
Then, either:
In the service it has something to indicate its status as running which can be captured by the web app to see it, or,
In the web, there is mechanism to request/monitor the service status
Is quite flexible I think. I would go with whichever is easier.
I picked the task scheduler option for my case. It was easier to implement the manual triggering by users mechanism.
Pros - Triggers can be added easly using the taks scheduler library.
I need to create an application that will run on a server and be able to be configured to run commands at certain times. For instance, there will be a web interface allowing a user to set an engage time and a disengage time. Once those values have been saved by the user I need for the server to be able to fire off those commands precisely at the time specified each day.
I would also need to be able to set single use non recurring events that would occur... maybe 10 minutes from the time an event was triggered and have a command fired off when that 10 minute timer goes off.
I've already got a class library written that has the engage and disengage commands exposed. I would hope to be able to integrate this into whatever solution I end up with and simply be able to make calls directly to the class. Alternatively I could also compile the class library into an executable and have commands issued to it via command line. I'm hoping to not have to do the latter.
I've never written anything like this before. I've peeked a bit at Windows Services, but there is a lot of chatter out there saying that it isn't necessarily the best option. Can someone please guide me in the right direction please?
A windows service is not a bad idea, its perfect for this kind of application. Unless you end up using standard windows scheduled tasks as the trigger for your command, you need some sort of process that is always running to contain your scheduler. A windows service is an excellent candidate for this.
Using a windows service in conjunction with Quartz.NET and some sort of persistence layer so you can store your schedules (in case you need to restart the service or it crashes etc) would be a good way to go.
Alternatively, you could write an application that just adds and removes windows scheduled tasks, but considering you have existing class libraries, using Quartz.NET will fit in well with your existing libraries.
easiest solution:
make a console exe and run under scheduled task in windows.
Let web page to accept user input and modify a configuration file.
I need to write a program in .NET which runs every few hours and does some task. It does not require user interaction but it needs a configuration file like App.config where I can put that configuration information.
So should I write console program in C# ( like php or perl script) and schedule it in task manager ( like crontab) or write a Windows Service or something else?
If you want scheduling capabilities and that schedule needs to be very configurable, a windows scheduled task does that pretty well. You would write that as a console app.
However, I would suggest a service for most things. Here is a great tutorial that talks about how to create windows services. Its much easier than you think.
http://www.switchonthecode.com/tutorials/creating-a-simple-windows-service-in-csharp
My suggestion would be to go for the console app and use the task manager.
It saves you from having to implement a custom timer
It gives you elaborate control over timing
It saves you from having to implement an UI
It gives you automation options, like piping in- and output at the command line
Depending on the complexity of your task the best option would be to create an application which can be run via a task scheduler. If you need to run something every few hours a windows service would also work, but remember if you create a windows service then you will have to use a timer control within your application which might hang up without giving any clues. There are lots of examples for both the concepts and instead of using windows service you can use Window Communication Foundation (WCF).
I am looking to program a simple "data push" service, that extracts data out of a SQL Server database, and deposits a CSV file to a remote FTP site every ten minutes. This service will be running on a remote server, managed over TeamViewer.
There are a few ways I've thought to do this, but would like a bit of advice as to which is the best and most reliable method. A few pro's and cons would also be very helpful from people who have experience in this type of work.
Possible solutions:
Windows service with use of Thread.Sleep(..) to run task every ten minutes
Simple EXE console project that runs as a Windows Scheduler task
Windows service with use of a Timer class
Any other methods?
The program will be written in C#, but I am very flexible in terms of project type, design etc.
The main requirement of this service is to be reliable, and I'd also look to build in an alerts system to notify on failure.
Many thanks
I would favour a scheduled task for this kind of application, as it's far easier to make changes to the schedule at a later date.
There's a previous question along a similar line here: Windows Service or Task Scheduler for maintenance tasks?
I have a project that get daily securities end of day values from the web and store them in a database.
I want it to happen once a day at a specific hour.
What is the best approach for that kind of need?
The simplest way:
Create a console app to perform the task and use the Windows task scheduler to run it at the desired time and interval.
You could also create a Windows Service but these are harder to deploy and debug than a console app.
(easiest first)
Schedule your application using Windows Scheduler
Implement a Windows Service and use Quartz .NET for scheduling
Implement scheduling manually and just keep your application running forever
You have a LOT of options, all with pros and cons. Just to name a few :
A loop that would keep your application running in the background.
A schedule agent that would launch your application once a day.
Using Windows Scheduler.
Another third party (or your own) scheduling application.
Given so little information, anything I'd be telling you about which is best for you wouldn't be worth a byte!
Option1: You can do it in your Csharp code using the date time check inside a timer control that triggers on regular interval. This approach is bad since it requires your application running continuously.
Option2: You can use a scheduled task in your OS and run the application at the specific hour to attain the same. My company follows this to generate automatic reports
Option3: You can use a windows service.(A Simple window service tutorial)
Here is a link that will help you decide whether to choose a scheduled task or a windows service.
Check out this post http://www.codeproject.com/KB/cs/Midnight_Timer.aspx and change it from midnight to the time you require.