使用石英作业调用应用程序
Call application using quartz job
我想编写将调用我安装的应用程序的 quartz 作业。
例如我有控制台应用程序:
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
}
}
我该怎么做?
在您的 Execute()
方法中,调用您需要调用的应用程序可执行文件:
// eg: "C:/MyApp/app.exe"
System.Diagnostics.Process.Start("PathToApplication.exe");
我想编写将调用我安装的应用程序的 quartz 作业。
例如我有控制台应用程序:
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
}
}
我该怎么做?
在您的 Execute()
方法中,调用您需要调用的应用程序可执行文件:
// eg: "C:/MyApp/app.exe"
System.Diagnostics.Process.Start("PathToApplication.exe");