使用石英作业调用应用程序

时间:2017-07-24 10:10:27

标签: c# console-application quartz.net

我想写一个石英作业,它将调用我已安装的应用程序。

例如我有控制台应用程序:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Datetime.Now());
        Console.ReadLine();
    }
}

我在我的Windows机器上发布了这个应用程序。现在我写下这段代码:

class Program
{
    static void Main(string[] args)
    {
        var schedFact = new StdSchedulerFactory();

        var sched = schedFact.GetScheduler();
        sched.Start();

        var job = JobBuilder.Create<TestJob>()
            .WithIdentity("testjob", "testgroup")
            .Build();

        var trigger = TriggerBuilder.Create()
            .WithIdentity("testtrigger", "testgroup")
            .WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever())
            .Build();

        sched.ScheduleJob(job, trigger);
    }

}


public class TestJob : IJob
{
    public void Execute(IJobExecutionContext context)
    {
        // Here I want to call my app
    }
}

我该怎么做?

1 个答案:

答案 0 :(得分:1)

Execute()方法中,调用您需要调用的应用程序可执行文件:

// eg: "C:/MyApp/app.exe"
System.Diagnostics.Process.Start("PathToApplication.exe");

MSDN Documentation