473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Scheduled tasks

Hi,

Does anybody know how to get an application do something at a specific
time or date? I want to be able to choose when to back up some files,
for example once a month, once a week or every hour.

Thanks!

May 21 '07 #1
4 2114
cj
I use a timer and in the tick event I check to see if it's time to do
whatever.

AxOn wrote:
Hi,

Does anybody know how to get an application do something at a specific
time or date? I want to be able to choose when to back up some files,
for example once a month, once a week or every hour.

Thanks!
May 21 '07 #2
On May 21, 8:27 am, AxOn <hannu_tahvanai...@hotmail.comwrote:
Hi,

Does anybody know how to get an application do something at a specific
time or date? I want to be able to choose when to back up some files,
for example once a month, once a week or every hour.

Thanks!
Take a look at:

http://msdn2.microsoft.com/en-us/library/aa394601.aspx

May 21 '07 #3
AxOn <ha***************@hotmail.comwrote in news:1179750430.559255.323620
@36g2000prm.googlegroups.com:
Hi,

Does anybody know how to get an application do something at a specific
time or date? I want to be able to choose when to back up some files,
for example once a month, once a week or every hour.
If your app is going to run infrequently and doesn't need to be aware of
state, I would use Windows Schedulerto handle scheduling:

http://www.codeproject.com/csharp/tsnewlib.asp

Otherwise you can use the timer classes.
May 21 '07 #4
AxOn,

Here is some sample code I got awhile back which may help:

Create a class to hold the information about each job:

Public Class Job
Public Name As String
Public ScheduledDT As DateTime
Public Msg As String
End Class

Store instances of Job to represent each event in an ArrayList.
Then you pass this ArrayList to scheduleJobs() which will add each event to
a HashTable and create a Timer for it:

Code:

Public Class Form1
Inherits System.Windows.Forms.Form

Private Jobs As New Hashtable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' build some test jobs to be scheduled (you would build these from
your XML files)
Dim j As Job
Dim jal As New ArrayList

j = New Job
j.Name = "Event1"
j.Msg = "Wake up!"
j.ScheduledDT = DateTime.Now.AddSeconds(30)
jal.Add(j)

j = New Job
j.Name = "Event2"
j.Msg = "Reset Alarm Clock"
j.ScheduledDT = DateTime.Now.AddSeconds(31)
jal.Add(j)

j = New Job
j.Name = "Event3"
j.Msg = "Reset Alarm Clock Again"
j.ScheduledDT = DateTime.Now.AddSeconds(45)
jal.Add(j)

j = New Job
j.Name = "Event4"
j.Msg = "Crawl out of bed..."
j.ScheduledDT = DateTime.Now.AddSeconds(60)
jal.Add(j)

scheduleJobs(jal)
End Sub

Private Sub scheduleJobs(ByVal JobAL As ArrayList)
Dim j As Job
Dim t As System.Timers.Timer
Dim ms As Double

For Each j In JobAL
ms = j.ScheduledDT.Subtract(DateTime.Now()).TotalMillis econds
If ms 0 Then ' if the event time has not yet passed...
t = New System.Timers.Timer(ms)
AddHandler t.Elapsed, AddressOf Me.t_Elapsed
Jobs.Add(t, j)
t.AutoReset = False ' fire it only once
t.Start()
End If
Next
Debug.WriteLine("---------------------")
Debug.WriteLine(Jobs.Count & " Job(s) Scheduled")
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
Dim t As System.Timers.Timer = CType(sender, System.Timers.Timer)
Dim j As Job = CType(Jobs.Item(t), Job)

' do something with the job
Debug.WriteLine("---------------------")
Debug.WriteLine(j.Name)
Debug.WriteLine(j.ScheduledDT)
Debug.WriteLine(j.Msg)

' remove the job from the hashtable and destroy the timer
Jobs.Remove(t)
t.Dispose()

Debug.WriteLine("---------------------")
Debug.WriteLine(Jobs.Count & " Job(s) Left")
End Sub
End Class
Hope this helps,

Steve
Jun 4 '07 #5

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

Similar topics

5
by: Bart Simpson | last post by:
Hi, I want to control 'Scheduled Tasks' in Windows 2003 by python program. But I couldn't find any Python module about win32 'Scheduled Tasks'. I could find only Perl module about it. (see...
4
by: Colin Steadman | last post by:
We have a number of scheduled tasks on our IIS server that run daily at some point during the early morning. These tasks run as a specific user that has the correct permissions to perform whatever...
6
by: John Bowman | last post by:
Hi, I have a C# app that needs to launch the "Add Scheduled Tasks" wizard found in the control panel "Scheduled Tasks" applet. I realize that this "applet" really just opens the tasks folder,...
3
by: Lenn | last post by:
Hi, I developed a console .exe application which is going to run on scheduled basis, it will be scheduled to run in Windows Scheduled tasks. Client wants some kind of utility that would help them...
3
by: kj7ny | last post by:
How can I access and manipulate Scheduled Tasks in Windows using Python? I have a Windows XP workstation running Python 2.4.4 using the win32all modules to control the windows services on...
0
by: kkkanoor | last post by:
I am trying to schedule tasks in Windows from my C# program. The tasks get listed in Windows Schedule Tasks list, but it is not getting invoked. It seems I need to give the user name and password to...
0
by: Paulson | last post by:
Dear Freinds I want to make a program that acts as a reminder for the users.I need to open up the Scheduled task wizard programmatically.If you type Tasks in the run command the Tasks...
1
by: naveensrirangam | last post by:
We want to do a total 10 number of scheduled tasks daily. These tasks will run in certain time in daily and every task application developed in different technologies . Now we are looking to do...
0
by: BD | last post by:
I'm running 8.2 on Windows. I have a situation where several scheduled tasks were created in Task Center, under an ID of a person who is leaving the organization. This person's ID is to be...
2
by: thj | last post by:
Hi, Is it possible to start an scheduled task on a server from ASP.NET? Thanks in advance. Tommy.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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,...

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.