这样的封装就赋予框架新的技能,大大提高了开发人员的开发效率。
主要代码using System;
using System.Collections.Generic;
using System.Linq;
using Topshelf;
namespace HSCP.Task
{
class Program
{
static void Main(string[] args)
{
HostFactory.Run(x =>
{
x.Service<MainService>((s) =>
{
s.ConstructUsing(settings => new MainService());
s.WhenStarted(tr => tr.Start());
s.WhenStopped(tr => tr.Stop());
});
x.RunAsLocalSystem();
x.SetDescription(\"\");
x.SetDisplayName(\"xxxx任务管理器\");
x.SetServiceName(\"HSCP.Task\");
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
namespace HSCP.Task
{
class MainService
{
static IScheduler sched;
public void Start()
{
try
{
ISchedulerFactory factory = new StdSchedulerFactory();
sched = factory.GetScheduler();
sched.Start();
Console.WriteLine($\"共 {sched.GetJobGroupNames().Count} 任务\");
foreach (string gn in sched.GetJobGroupNames())
Console.WriteLine(gn);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
// NLogger.Info(string.Format(\"启动成功 {0}\", DateTime.Now));
}
public void Stop()
{
sched.Shutdown(true);
}
}
}
https://github.com/quartznet/quartznet
