This project has moved and is read-only. For the latest updates, please go here.

Unable to invoke task.Run

Topics: Errors
Sep 19, 2013 at 12:57 PM
Edited Sep 19, 2013 at 1: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
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?
Sep 19, 2013 at 4:48 PM
Edited Sep 23, 2013 at 11: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

    ' 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 11:16 AM
Edited Sep 20, 2013 at 11: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
Sep 20, 2013 at 3:21 PM
Edited Sep 23, 2013 at 11: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.

td.Actions.Add(New ExecAction("cmd", "/c start Log /min " + ConfigurationSettings.AppSettings("consoleAppExeFilePath") + "$(Arg0) $(Arg1) $(Arg2) $(Arg3) $(Arg4) $(Arg5)"))
Sep 23, 2013 at 12:25 PM
I tried using the format you specified. Still gives the same error
Sep 23, 2013 at 11:48 PM
I have corrected errors in my previous code samples in this thread. I believe they should work now.
Sep 24, 2013 at 8: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?
Sep 24, 2013 at 8:23 PM
The Run method forces the task's action(s) to be run immediately regardless of any trigger settings.
Sep 25, 2013 at 6:29 AM
Thank you for your help.