In article <e#**************@TK2MSFTNGP14.phx.gbl>, Brian Henry wrote:
cant do that, this needs to be a windows service that will be doing
different tasks in the application dependent on a custom schedule users set
up on their client systems... kind of like scheduled reporting and such
You can still use the task scheduler... In the windows service, you
could override the ServiceBase.OnCustomCommand method. This allows your
service to receive a custom command with a numeric value in the range of
128 to 256. So, you could associate a numeric value with each of the
tasks (it could be a TaskType enum :).
Then, you have your windows program that is the interface that the user
sets up the schedule. The schedule is a task in the task scheduler.
What the task run is a simple little windows program with no gui that
takes the task number on the command line. All the program does is
simply call your services OnCustomCommand method:
Dim myService As ServiceController = New ServiceController ("MyServiceName")
If myService.Status = ServiceControllerStatus.Running Then
myService.ExecuteCommand (Convert.ToInt32 (args(0))
End IF
You service would might do something like:
Protected Override Sub OnCustomCommand (ByVal command As Integer)
' You might use the ThreadPool to que a job or you could spawn
' a thread if you like.
Select Case command
Case 128
' code to stick the associated command into a thread pool?
Case 129
' code to stick the associated command into a thread pool?
End Select
End Sub
Now, sticking the actual task in the task scheduler is the hardest part
- fortunately, there are several .NET libraries to accomplish this :)
Here is one I wrote:
http://mtogden.com/~tom/files/SchedulingAgent.NET.zip
It is the C# source code. Anyway, that is one idea :)
--
Tom Shelton