vishu minhas vishu minhas - 1 year ago 176
C# Question

How to pass argument while calling Task Scheduler from c#

Here I have create service for writing .txt file and passing parameter from Task scheduler using this code :

static void Main(string[] args)
{

string abc = string.Empty;
foreach (var item in args)
{
abc += item +" ";
}
string path = @"D:\GST Project\Demo Text File.txt";
File.WriteAllText(path, abc);
}


I have added the task in task scheduler like this:
Task scheduler

I want to call my scheduler task by using C# code below is my code which I have taken from Link

using (TaskService tasksrvc = new TaskService(server.Name, login, domain, password))
{
Task task = tasksrvc.FindTask(taskName);
task.Run();
}


I am wondering here how we can pass the parameter through TaskService. Also
What should I pass in place of Server.Name,login, domain,Password.
Thanks for your help !

Answer Source

try the below code:- This will help you

TaskService.Instance.AddTask("Test", QuickTriggerType.Daily, "Exe file path", "test");

this will schedule your task and pass the test argument in your exe file

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download