VB.NET Code for creating a scheduled task (.job)

  • Thread starter Thread starter Max
  • Start date Start date
M

Max

I'm writing a program that needs to be able to create custom .job files
and add them to the scheduled tasks folder. What I'd like to know is,
what is the format of a .job file and how do I go about adding in all
the data so that the task could run correctly?

If that is something not so easy to do, then say I need a certain part
of my program to execute on a schedule... How do I go about writing some
internal scheduling routine that won't utilize a lot of CPU power while
the program is running?

Thanks for any advice.
 
Max said:
I'm writing a program that needs to be able to create custom .job
files and add them to the scheduled tasks folder. What I'd like to
know is, what is the format of a .job file and how do I go about
adding in all the data so that the task could run correctly?

If that is something not so easy to do, then say I need a certain
part of my program to execute on a schedule... How do I go about
writing some internal scheduling routine that won't utilize a lot of
CPU power while the program is running?

Thanks for any advice.

I only found this one...

http://msdn.microsoft.com/library/en-us/taskschd/taskschd/task_scheduler_start_page.asp

....but don't know how to implement it in VB.Net.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
I'm writing a program that needs to be able to create custom .job files
and add them to the scheduled tasks folder. What I'd like to know is,
what is the format of a .job file and how do I go about adding in all
the data so that the task could run correctly?

If that is something not so easy to do, then say I need a certain part
of my program to execute on a schedule... How do I go about writing some
internal scheduling routine that won't utilize a lot of CPU power while
the program is running?

Thanks for any advice.

Go and get http://www.mtogden.com/~tom/files/SchedulingAgent.NET.zip.
This is a class library I wrote while I was initialy playing with C#.
This is callable from VB.NET. You just need to include the project in
your solution and reference it. You can look at the task scheduler
documentation on MSDN to get an idea about what each property does.
There may be a couple that aren't implemented - but since you have the
source...
 
Tom said:
Go and get http://www.mtogden.com/~tom/files/SchedulingAgent.NET.zip.
This is a class library I wrote while I was initialy playing with C#.
This is callable from VB.NET. You just need to include the project in
your solution and reference it. You can look at the task scheduler
documentation on MSDN to get an idea about what each property does.
There may be a couple that aren't implemented - but since you have the
source...

Ok thanks for that, I'll have a look. However, just after taking a quick
look I can't figure out what you used to write those files. VS.NET
doesn't recognize any of those files and only opens them in text mode
(no syntax or anything else like that). Doesn't recognize
SchedulingAgent.csproj as a project file either. What do I do about this?
 
Max said:
I'm writing a program that needs to be able to create custom .job
files and add them to the scheduled tasks folder. What I'd like to
know is, what is the format of a .job file and how do I go about
adding in all the data so that the task could run correctly?

If that is something not so easy to do, then say I need a certain part
of my program to execute on a schedule... How do I go about writing
some internal scheduling routine that won't utilize a lot of CPU power
while the program is running?

Thanks for any advice.


All right, this is proving to be far more complex then I need for it to
be and I don't really like the idea of the user being able to change the
schedule outside of the program. What I'm thinking right now, how would
it be possible to implement a simple scheduler myself? I'm going to have
a few tasks that the program needs to execute on a given schedule, for
every task I will determine the next time it needs to be run (date and
time), and after that all I need is some kind of a trigger when that
time comes. So how can I do this? Timers maybe, but I don't know how
good that will be for the CPU. This program will be running 24/7 in the
background, so unless it's running a task it needs to minimize resource
usage. Please let me know.
 
Ok thanks for that, I'll have a look. However, just after taking a quick
look I can't figure out what you used to write those files. VS.NET
doesn't recognize any of those files and only opens them in text mode
(no syntax or anything else like that). Doesn't recognize
SchedulingAgent.csproj as a project file either. What do I do about this?

Interesting... Those are my VS.NET 2003 project files. I simply
deleted the bin and obj directory and zipped it up. Are you using
VS.NET 2002? That's what I originally did the project in, but I have
long since converted it to 2003...

Anyway, if you have to - just create a new C# class library project, and
copy the files over and add them to the project.
 
Max said:
All right, this is proving to be far more complex then I need for it
to be and I don't really like the idea of the user being able to
change the schedule outside of the program. What I'm thinking right
now, how would it be possible to implement a simple scheduler myself?
I'm going to have a few tasks that the program needs to execute on a
given schedule, for every task I will determine the next time it needs
to be run (date and time), and after that all I need is some kind of a
trigger when that time comes. So how can I do this? Timers maybe, but
I don't know how good that will be for the CPU. This program will be
running 24/7 in the background, so unless it's running a task it needs
to minimize resource usage. Please let me know.


Anyone???
 
All right, this is proving to be far more complex then I need for it to
be and I don't really like the idea of the user being able to change the
schedule outside of the program. What I'm thinking right now, how would
it be possible to implement a simple scheduler myself? I'm going to have
a few tasks that the program needs to execute on a given schedule, for
every task I will determine the next time it needs to be run (date and
time), and after that all I need is some kind of a trigger when that
time comes. So how can I do this? Timers maybe, but I don't know how
good that will be for the CPU. This program will be running 24/7 in the
background, so unless it's running a task it needs to minimize resource
usage. Please let me know.

Max,

When you create a job using the task scheduler, set the Job's hidden
property to true. Then it won't show up in the task scheduler
interface. Do you need some sample code of actually using the library?

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
"`The best way to get a drink out of a Vogon is to stick
your finger down his throat...'"

- The Book, on one of the Vogon's social inadequacies.
 
Tom said:
Max,

When you create a job using the task scheduler, set the Job's hidden
property to true. Then it won't show up in the task scheduler
interface. Do you need some sample code of actually using the library?

Well the reasons I decided not to use the scheduler are, first, that it
doesn’t provide me with the flexibility that I need. Sure I could just
come up with 20 different rules or whatever, but that just seems to be
an unnecessary complexity. Also, if I use the task scheduler then the
way I have to implement my program is that the user starts it up,
configures some tasks, then shuts the program down (after it added the
task to the scheduler), and then when the task is executed the program
has to start back up again. It can't be running 24/7 because when the
task is executed there is no way for the program to know that, the task
has to be the one that starts it. Since I do want the program to run
24/7 my own scheduler seems a better way to go. Not to mention that I
already have the code that goes through all the tasks and correctly
calculates the next task to be run, at what time, and at what date. Now
all I need is a routine that will wait for that time and date and run a
single function.

On the other hand, if you don't mind I would still like to see an
implementation of your library just in case I need it for the future.
 
Back
Top