Unable to invoke task.Run

Topics: Errors
Sep 19, 2013 at 11:57 AM
Edited Sep 19, 2013 at 12:12 PM
td.Actions.Add(new ExecAction("myprogram.exe", "$(Arg0),$(Arg1),$(Arg2)"));
task.Run("A", "B", "C");
I am unsure what task refers to.
My code:
objTaskService = New TaskService
Dim objTrigger As New DailyTrigger
objTrigger.StartBoundary = dtStartDate
Dim objTask = objTaskService.NewTask
objTask.Actions.Add(objAction)
objTask.Triggers.Add(objTrigger)
objTaskService.RootFolder.RegisterTaskDefinition("Log", objTask)
On which instance should i invoke the "Run"method?
Can we pass variables instead of string parameters to the Run method?
Coordinator
Sep 19, 2013 at 3:48 PM
Edited Sep 23, 2013 at 10:46 PM
Here is some working code that does what I think you're asking. You can pass string typed variables to the Run method.
Using ts As New TaskService()
    ' Create a new task definition
    Dim td As TaskDefinition = ts.NewTask

    ' Add a daily trigger
    Dim dt As New DailyTrigger()
    dt.StartBoundary = dtStartDate
    td.Triggers.Add(dt)

    ' Add an action that takes parameters
    td.Actions.Add(New ExecAction("myprogram.exe", "$(Arg0) $(Arg1) $(Arg2)"))

    ' Register the task in the root folder
    Dim task As Task = ts.RootFolder.RegisterTaskDefinition("Test", td)

    ' Run the task immediately with parameters
    task.Run("A", var1, "C")
End Using
Sep 20, 2013 at 10:16 AM
Edited Sep 20, 2013 at 10:16 AM
Thankyou for the quick reply

I am still facing problems defining the ExecAction instance.
td.Actions.Add(New ExecAction("cmd", "/c start ""Log"" /min " + ConfigurationSettings.AppSettings("consoleAppExeFilePath") + " " + var1 + " " + var2 + " " + var3.ToString + " " + dtEndDate + " " + dtStartDate + " " + var4, Nothing)
I'm trying to rewrite the above code using Arguments as follows:
td.Actions.Add(New ExecAction("cmd", "/c start ", "Log", " /min", ConfigurationSettings.AppSettings("consoleAppExeFilePath"), "$(Arg0)", "$(Arg1)", "$(Arg1)", "$(Arg1)", "$(Arg1)", "$(Arg1)"))
Dim task As Task = ts.RootFolder.RegisterTaskDefinition("Test", td)
task.Run(var1, var2, var3.ToString, dtEndDate, dtStartDate, var4)
It does not work.
I get the following error at ExecAction:
Error   11  Overload resolution failed because no accessible 'New' accepts this number of arguments.
Help appreciated
Coordinator
Sep 20, 2013 at 2:21 PM
Edited Sep 23, 2013 at 10:47 PM
The ExecAction constructor takes a comma separated list of string constants. If variables are supplied to this constructor, they must evaluate to strings and cannot be replaced at runtime. The only arguments that can be evaluated at runtime are those in the $(ArgX) format where X represents the numerical order of the parameter in the Run method.

Try:
td.Actions.Add(New ExecAction("cmd", "/c start Log /min " + ConfigurationSettings.AppSettings("consoleAppExeFilePath") + "$(Arg0) $(Arg1) $(Arg2) $(Arg3) $(Arg4) $(Arg5)"))
Sep 23, 2013 at 11:25 AM
I tried using the format you specified. Still gives the same error
Coordinator
Sep 23, 2013 at 10:48 PM
I have corrected errors in my previous code samples in this thread. I believe they should work now.
Sep 24, 2013 at 7:52 AM
Yes that works. Thank you for your time.
Just wanted to clarify : Using task.Run causes the task to be executed immediately and in this case, the StartBoundary of the DailyTrigger is not relevant?
Coordinator
Sep 24, 2013 at 7:23 PM
The Run method forces the task's action(s) to be run immediately regardless of any trigger settings.
Sep 25, 2013 at 5:29 AM
Thank you for your help.