473,487 Members | 2,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using time for scheduling task.

Hi all,

I want to develop one windows service in which i want to provide some
scheduling facility.

What i want is to take start time frm one xml file and then at that
specified start time.

Which timer should i use in windows service to start particular process
at user specified time.

Means how to do this. Should i add ontimerevent and write loop to
continuously check system time and user specified time.

Can someone tell me what is correct way of doing it,

Any help will be truely appreciated.

Thanks in advance.

Jun 13 '06 #1
4 16915
Any reason why you cant use the scheduler service built into windows?

Regards

John Timney (MVP)
"archana" <tr**************@yahoo.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Hi all,

I want to develop one windows service in which i want to provide some
scheduling facility.

What i want is to take start time frm one xml file and then at that
specified start time.

Which timer should i use in windows service to start particular process
at user specified time.

Means how to do this. Should i add ontimerevent and write loop to
continuously check system time and user specified time.

Can someone tell me what is correct way of doing it,

Any help will be truely appreciated.

Thanks in advance.

Jun 13 '06 #2
kh
archana

i have a scheduling Windows Service working using System.Timers.Timer and it
is perfectly adequate for this task. how you use the timer depends on your
needs, but you can do something like this easily enough..

System.Timers.Timer timer;
public MyService()
{
InitializeComponent();
timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}

protected override void OnStart(string[] args)
{
// set interval from config
try
{
this.timer.Interval =
Int32.Parse(System.Configuration.ConfigurationMana ger.AppSettings["TimerIntervalMinutes"]) * 60 * 1000;
}
catch
{
this.timer.Interval = 3600000;
}
timer.Start();
}

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timer.Stop();
try
{
// do something
}
finally
{
timer.Start();
}
}

Jun 13 '06 #3
Hi ,

Thanks for your reply.

But i want to implement functionality like allowing user to specify
start time and at that time only daily my task should run.

But timer is allowing me to set interval only.

What i did is i calcluated difference between current time and user
specified time and set that as a interval.

But my problem is for first time it is working properly but how will i
set timer interval to run it on next day at the same time.

If i am wrong please correct me.

Thanks.

kh wrote:
archana

i have a scheduling Windows Service working using System.Timers.Timer and it
is perfectly adequate for this task. how you use the timer depends on your
needs, but you can do something like this easily enough..

System.Timers.Timer timer;
public MyService()
{
InitializeComponent();
timer = new System.Timers.Timer();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}

protected override void OnStart(string[] args)
{
// set interval from config
try
{
this.timer.Interval =
Int32.Parse(System.Configuration.ConfigurationMana ger.AppSettings["TimerIntervalMinutes"]) * 60 * 1000;
}
catch
{
this.timer.Interval = 3600000;
}
timer.Start();
}

void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timer.Stop();
try
{
// do something
}
finally
{
timer.Start();
}
}


Jun 14 '06 #4
kh
this is exactly what i do. i only use the timer as a "heartbeat" for the main
scheduling functionality. in the Timer.Elapsed event handler i check if any
of my jobs are due. my jobs are actually configured in the App.config file,
but you could easily write something to do the following (most of the
supporting code has been omitted for clairity):

class MyService : ServiceBase
{
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timer.Stop();
try
{
foreach(Job j in myJobsCollection)
if(j.JobIsDue(DateTime.Now))
j.Run();
}
finally
{
timer.Start();
}
}
}

class Job
{
public bool JobIsDue(DateTime dt)
{
return dt.TimeOfDay >= mySpecifiedRunTime;
}
}

Jun 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5696
by: Jonas Granqvist | last post by:
I wonder if someone could help me with some sample code on how to make a simple application using time. How can I for instance make the program run the function "foobar()" every ten seconds? I've...
2
4134
by: Roel Castro | last post by:
Could somebody help me, how to prevent unauthorized users in changing the time/date either in task bar or control panel? Are there line of codes i can use within MS-ACCESS form modules to do this?...
1
2752
by: catherene | last post by:
hai, in IEEE software jan/feb 2003 an article was published regarding suitability of C# and .NET in real-time systems. can anybody is doing research on its analysis of schedulability. kindly...
17
6383
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
0
1290
by: Lemune | last post by:
Hello. I need some help on building my sms services application (using modem). My application is to do some scheduling task based on daily, weekly and monthly. On the daily the choice are everyday,...
1
1513
by: Adam42 | last post by:
Hi outthere, I'm looking for a highly modular time manager/task mananger which is (of course!) written in PHP. Any suggestions? Btw. the system shall be open source developed under a GNU...
5
2388
by: scriptee | last post by:
Hi , I wan to run a php script using cron on my host server. Its a Linux based server and I am allowed to use cron. I want to run a php script with includes. I tried some suggestions which...
2
4300
by: korean_dave | last post by:
Does anyone know how to properly kick off a script using Windows Scheduled Task? The script calls other python modules within itself. HERE'S THE CATCH: I am used to running the script directly...
0
1208
by: Andreas Tawn | last post by:
Does anyone know how to properly kick off a script using Windows Import os and add os.system("pause") at the end of AutomatedTestRun.py to keep cmd open. As far as not seeing any output, I...
0
6967
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...
0
7181
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...
1
6846
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...
0
7349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5442
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
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...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
267
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...

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.