从C#调用Task Scheduler时如何传递参数 [英] How to pass argument while calling Task Scheduler from c#

查看:796
本文介绍了从C#调用Task Scheduler时如何传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我已经创建了用于写入.txt文件并使用以下代码从任务计划程序传递参数的服务:

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);
    }

我已经在任务计划程序中添加了任务,如下所示:
< a href = https://i.stack.imgur.com/FNwqP.png rel = nofollow noreferrer>

I have added the task in task scheduler like this:

我想通过以下C#代码调用我的调度程序任务,这是我从链接

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();       
}

我想知道如何通过TaskService传递参数。还
我应该通过什么代替Server.Name,登录名,域,密码。
感谢您的帮助!

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 !

推荐答案

尝试以下代码:-
这将为您提供帮助

try the below code:- This will help you

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

这将安排您的任务并在exe文件中通过 test 参数

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

这篇关于从C#调用Task Scheduler时如何传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆