0

Using Visual Studio and C# I am trying to create a single program that can schedule a task in the Windows Task Scheduler and tell it to execute a portion of code / a function in the program.

Issue - From what it seems like, I need 2 programs -

  1. The program to create the scheduled task
  2. The program the task scheduler runs

However, I would like the user to only need to install 1 program, and then within that program it can create a task, as well as execute a program / script.

For creating the task I am using the Task Scheduler Managed Wrapper - Creating Scheduled Tasks And from that question I can see the user creates a task that runs a .exe. Is there anyway to get that to run a portion of the code in the current program? Or is there a way that I can create 2 executables that can both go under one installation?

Just not really sure how to approach this, so any help is appreciated.

Community
  • 1
  • 1
Adjit
  • 10,134
  • 12
  • 53
  • 98

1 Answers1

0

You can use command line parameters to switch your program between "install a scheduled task" (which would probably be part of the default, parameterless flow) and "run the scheduled task" (specified by passing some parameter).

You then schedule your own application with the correct parameters to execute the desired task.

Paul-Jan
  • 16,746
  • 1
  • 63
  • 95
  • Ok, that makes sense. Do you think that would be better versus 2 executables? – Adjit Jul 17 '16 at 14:32
  • That's a question only you can answer, it depends very much on your situation and personal taste. In general, yes, I'd personally prefer to use a single executable. An extra executable is an extra point of failure during updates/deployment. – Paul-Jan Jul 17 '16 at 14:36
  • However, if for example the task to schedule is wildly different from the things your main application does, then a second executable might make sense. – Paul-Jan Jul 17 '16 at 14:37