Task
class has Run
and Stop
methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.Please provide a FULL and CLEAR explanation of your problem. If I had to guess (which I do) then I'd say that you are probably using this NuGet package. I wasn't even aware that that existed until a few minutes ago but I found it with a web search, clicked the API documentation link and then followed a few more links to see that theTask
class hasRun
andStop
methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.
using System;
using Microsoft.Win32.TaskScheduler;
class Program
{
static void Main()
{
// Get the service on the remote machine
using (TaskService ts = new TaskService(@"\\RemoteServer", "username", "domain", "password"))
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
// Register the task in the root folder.
// (Use the username here to ensure remote registration works.)
ts.RootFolder.RegisterTaskDefinition(@"Test", td, TaskCreation.CreateOrUpdate, "username");
}
}
}
using (TaskService ts = new TaskService())
{
string task = "Target scheduler";
Task t = ts.FindTask(task);
if (t != null)
{
TaskDefinition td = ts.FindTask(task);
// Change argument values in scheduler
td.Actions.Add(new ExecAction("notepad.exe", "Argument", null));
ts.RootFolder.RegisterTaskDefinition("AppName", td, TaskCreation.CreateOrUpdate);
}
}
Please provide a FULL and CLEAR explanation of your problem. If I had to guess (which I do) then I'd say that you are probably using this NuGet package. I wasn't even aware that that existed until a few minutes ago but I found it with a web search, clicked the API documentation link and then followed a few more links to see that theTask
class hasRun
andStop
methods. I'm guessing that those are what you're after but it's hard to say for sure with so little information to go on.
The documentation says that that's where commandline arguments go so presumably so. I can't tell you more than that because I've never used this library myself. As I said, I had no idea it even existed until I read this question. It's time for you to test it for yourself and see what happens. You don't need to ask us anything that you can test for yourself. Just create a console app that doesn't nothing but output its commandline arguments and then try creating a scheduled task to run it using code like that. If it works then you know it works and if it doesn't then you know it doesn't. Iterative testing like that is a fundamental part of software development.So, can I just modify the code like below?
Please teach me
Run
and Stop
on a Task
. I'm not sure what exactly it is that you want to be taught.