Need help writing a recurring task scheduler - windows

I need to write a tool that will run a recurring task on a user configurable schedule. I'll write it in C# 3.5 and it will run on XP, Windows 7, or Windows Server 2008. The tasks take about 20 minutes to complete. The users will probably want to set up several configurations: e.g, daily, weekly, and monthly cycles. Using Task Scheduler is not an option.
The user will schedule recurrences through an interface similar to Outlook's recurring appointment dialog. Once they set up the schedule they will start it up and it should sit in the system tray and kick off its tasks at the appointed times, then send mail to indicate it has finished.
What is the best way to write this so that it doesn't eat up resources, lock up the host, or otherwise misbehave?

The best thing you can do is avoid reinventing the wheel by leveraging what the OS provides. See the article Calling the Task Scheduler in Windows Vista (and Windows Server 2008) from managed code from Bart De Smet for a very to-the-point usage of the windows task scheduler from C#.
If for some reason you must implement your own service (e.g. greater control over dependencies), I'd look at some of the open source Cron implementations in .NET compatible languages. There is an article with code on code project named Implementing a small Cron service in C# that seems to do this. Based on his article An Event Based Cron (Scheduled) Job In C#, it looks like Bob Cravens has done some more thorough work in this area or at least documented his work more thoroughly. I'm sure there are others if you look around, and something based on Cron is a good starting point.

I will suggest writing a Windows Service that uses a SQlite db to get the schedules and
add a GUI to write whatever you need to the db but remember to use
System.Timers.Timer
and not the
System.Windows.Forms.Timer
In your Windows Service

Related

Scheduling console apps

Does anyone have better ways of managing / scheduling console apps, without the use of Windows Scheduler?
eg. Console app to pickup records in the database that requires a set of actions.
*** Experience in the past, when number of tasks increase over time, it get's bit messy and difficult to maintain when moving servers.
There are third party apps you could look at, some of which are suggested in Cron-like system for Windows?.
However, if Windows Scheduler does provide the functionality you need, but just not the ideal management, you could look at using the CLI schtasks.exe
You can define all your tasks in an XML schema meaning they will more easily port across machines.

Is it possible to run a visual studio solution automatically at random times of the day?

I have created a solution in visual studio, which is basically code to test the functionality of a website using an automated web driver. I would like to know the simplest way to run this solution periodically based on a set interval time, like at 2 am everyday or every 24 hours. For example, if some one knew how to use a scheduling system, script, or anything like these that could RUN the solution automatically, please contribute your knowledge. This information is mainly for newbies to Visual Studio like myself. Thanks much.
I found that to do this involves two things.
After writing your unit test, write a batch file that contains the MSTest.exe command to run the tests that you want. The batch file should change to the directory, rebuild the solution, and run your unit test.
Use the windows scheduler to schedule regular time intervals for executing the batch file.
More specific information on how to do this is available here.
Thanks for your kind attention.
If/when Visual Studio can support running multiple instances during development, you can use the built-in Windows 7 Task Scheduler (Start -> All Programs -> Administrative Tools -> Task Scheduler).
There are multiple tutorials available on the internet to assist you with setting up a recurring task in the Task Scheduler. Here is one example:
http://www.ampercent.com/using-windows-7-task-scheduler-to-run-any-installed-program/7744/

Quartz.NET vs Windows Scheduled Tasks. How different are they?

I'm looking for some comparison between Quartz.NET and Windows Scheduled Tasks?
How different are they? What are the pros and cons of each one? How do I choose which one to use?
TIA,
With Quartz.NET I could contrast some of the earlier points:
Code to write - You can express your intent in .NET language, write unit tests and debug the logic
Integration with event log, you have Common.Logging that allows to write even to db..
Robust and reliable too
Even richer API
It's mostly a question about what you need. Windows Scheduled tasks might give you all you need. But if you need clustering (distributed workers), fine-grained control over triggering or misfire handling rules, you might like to check what Quartz.NET has to offer on these areas.
Take the simplest that fills your requirements, but abstract enough to allow change.
My gut reaction would be to try and get the integral WinScheduler to work with your needs first before installing yet another scheduler - reasoning:
no installation required - installed and enabled by default
no code to write - jobs expressed as metadata
integration with event log etc.
robust and reliable - good enough for MSFT, Google etc.
reasonably rich API - create jobs, check status etc.
integrated with remote management tools
security integration - run jobs in different credentials
monitoring tooling
Then reach for Quartz if it doesn't meet your needs. Quartz certainly has many of these features too, but resist adding yet another service to own and manage if you can.
One important distinction, for me, that is not included in the other answers is what gets executed by the scheduler.
Windows Task Scheduler can only run executable programs and scripts. The code written for use within Quartz can directly interact with your project's .NET components.
With Task Scheduler, you'll have to write a shell executable or script. Inside of that shell, you can interact with your project's components. While writing this shell code is not a difficult process, you do have to consider deploying the extra files.
If you anticipate adding more scheduled tasks over the lifetime of the project, you may end up needing to create additional executable shells or script files, which requires updates to the deployment process. With Quartz, you don't need these files, which reduces the total effort needed to create and deploy additional tasks.
Unfortunately, Quartz.NET job assemblies can't be updated without restarting the process/host/service. That's a pretty big one for some folks (including myself).
It's entirely possible to build a framework for jobs running under Task Scheduler. MEF-based assemblies can be called by a single console app, with everything managed via a configuration UI. Here's a popular managed wrapper:
https://github.com/dahall/taskscheduler
https://www.nuget.org/packages/TaskScheduler
I did enjoy my brief time of working with Quart.NET, but the restart requirement was too big a problem to overcome. Marko has done a great job with it over the years, and he's always been helpful and responsive. Perhaps someday the project will get multiple AppDomain support, which would address this. (That said, it promises to be a lot of work. Kudos to he and his contributors if they decide to take it on.)
To paraphrase Marko, if you need:
Clustering (distributed workers)
Fine-grained control over triggering or misfire handling rules
...then Quartz.NET will be your requirement.

db2 time based trigger

are there any time based triggers in DB2?
You don't have to. There is usually a OS function available for that. If I am not mistaken it is at in unix and the scheduled jobs under windows (there is also a command line interface for windows).
However, I do remember that there was a scheduler in MS SQL server. After asking google, I learned that DB2 has something called task center. Not sure what that thing does or how you configure it (my UI does not open for some strange reason).
Without further details, I can't give you a specific answer. I'm guessing you're asking for "a trigger that is fired at a specific time" and not "a trigger that has different timing options, like fire before event or fire after event".
The answer to the former is no, triggers are not fired by external events like the time of day. Triggers are features specifically designed to respond to monitor for changes in tables. What you are looking for is some form of task/job scheduling, and there are many approaches you can use to accomplish this.
I can't really detail any options without knowing what platform you're running on (Unix, Linux, Mainframe, Windows?), so if you could clarify I might be able to help further. The version of DB2 you're running would also help.
Examples
If you're running DB2 on IBM's iSeries you would probably want to use the OS's native job scheduler (see http://publib.boulder.ibm.com/infocenter/iseries/v6r1m0/topic/rzaks/sc415324.pdf).
On Unix/Linux the popular option is cron (see http://www.adminschoice.com/crontab-quick-reference)
The typical solution for DB2 on windows, z/OS, and others is the Task Center utility (depending on your DB2 version, see http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.taskcenter.doc/taskcenter/abouttaskcenter.htm)

Practical Alternative for Windows Scheduled Tasks (small shop)

I work in a very small shop (2 people), and since I started a few months back we have been relying on Windows Scheduled tasks. Finally, I've decided I've had enough grief with some of its inabilities such as
No logs that I can find except on a domain level (inaccessible to machine admins who aren't domain admins)
No alerting mechanism (e-mail, for one) when the job fails.
Once again, we are a small shop. I'm looking to do the analogous scheduling system upgrade than I'm doing with source control (VSS --> Subversion). I'm looking for suggestions of systems that
Are able to do the two things outlined above
Have been community-tested. I'd love to be a guinae pig for exciting software, but job scheduling is not my day job.
Ability to remotely manage jobs a plus
Free a plus. Cheap is okay, but I have very little interest in going through a full blown sales pitch with 7 power point presentations.
Built-in ability to run common tasks besides .EXE's a (minor) plus (run an assembly by name, run an Excel macro by name a plus, run a database stored procedure, etc.).
I think you can look at :
http://www.visualcron.com/
Consider Cygwin and its version of "cron". It meets requirements #1 thru 4 (though without a nice UI for #3.)
Apologize for kicking up the dust here on a very old thread. But I couldn't disagree more with what's been presented here.
Scheduled tasks in Windows are AWESOME (a %^#% load better than writing services I might add). Yes, not without limitations. But still extremely powerful. I rely on them in earnest for a variety of different things.
If you even have a slight grasp on c# you can write as custom "task" (essentially a console application) to do, well, virtually anything. If persistent/accessible logging is what you're after, why not something like Serilog or NLog? Even at the time of writing, it had a very robust feature set. This tool in and of itself, in conjunction with some c#, could've solved both your problems very easily.
Perhaps I'm missing the point, but it seems to me that this isn't really a problem. At least not anymore...
If you're looking for a free tool there is plenty of implementations for the popular Cron tool for Windows, for example CRONw. It's pretty easy to configure and maintain. You could easily write add custom WSH scripts to send your emails and add log entries.
If you're going commercial way BMC Control-M is arguably one of the best but I don't believe that it is particularly cheap.
You may also consider some upcoming packages like JobScheduler
Pretty old question, but we use Jenkins. Yes its main purpose is for CI\CD, but its also a really nice UI for CRON with a ton of plugins and integrations.

Resources