Click here to Skip to main content
1,837 members
Articles / Security / .NET 3.5
Article

A Crontab Linux like Windows Service

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 May 2012CPOL 11K   1  
A Windows Service that uses interface to work like the Linux Crontab service

What is Windows Service Manager?

It is a CRONTAB Linux like Windows service that allows you to specify applications that must be performed in a very flexible and scheduled way. The intent is to run libraries in .NET in a well-planned target allowing each daily activity in a library to perform this activity as expected.

Image 1

In the picture above, we have the main components of this system that allow running any component that implements a standard interface, IService. This interface is based on the main methods of a service: Start(), Stop(), Pause(), and Continue().

OnStart() method

When starting the service, it reads the service processes that manage and execute the windows according to the schedule set. Each process must implement the interface IService that will allow the service window to manipulate the process in a manner similar to a service under Windows.

The method ReadCrontab() is responsible for reading the files to be executed.

ReadCrontab() method

Having defined the data source that contains the list of processes that must be run, the service takes care of, every 30 seconds, to check this list to instantiate and run any process that has been specified to run.

If that is the exact moment in which the case was set, then it is read from the assembly, instantiated, and executed, and any parameters passed to it are informed of the scheduling process.

DoCrontabItem() method

The service records of the process windows, and instantiates and runs - before an object "Item" is created that will allow the process to update the information recorded by the service windows at runtime - so if for some reason, the process is interrupted in unexpected windows of the service may, next time or is started, collect such information, instantiate and run the process so that it completes its task.

Implementing the IService Interface

The implementation of the interface is extremely simple and allows the service with windows to communicate with the process and vice versa. The process can, for example return any exception that occurs during the execution by setting the value for the property ItemException. The property "Success" indicates whether the process was executed without any error - it is based on the value of property "ItemException" to set this value: if the property is equal to "zero", then the return value is true.

Samples class diagram

The code available for download as an example contains two classes: Person and Address. The Address class contains only a statement of methods and Person class implements a very simple and didactic.

The implementation of person runs a loop which will record the progress of the process from the argument "Commom.Process.Item" until it is completed.

Sample implementation class

Disclaimer

My English is not so good and so I am not so inspired to explain further but the intention is to implement a solution in .NET that allows to run several processes similar to what is Linux Crontab.

If you wish to contribute in any way, please do so. I would like to improve this code and make it useful for more people.

I would also stress that not all the code available here is my complete authorship - unfortunately I did not find in my files the original articles to give due credit to those who rightly deserve it, but I can guarantee that all code here can be used and adapted as it is all free.

So be free.

History

This code is a long time work implementation stated when I began using C#. At that time, I didn't know reflection yet. This is the recent version updated on 2009-08-29.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) mmcWeb Solutions Sorocaba-SP Brazil
Brazil Brazil
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
-- There are no messages in this forum --