如何在 Quartz.Net 中让 Job 引发 EventHandler?
我有一个实例化 Quartz Scheduler 的控制台应用程序。
我希望作业能够引发事件处理程序,以便“母应用程序”调用特定的方法。
问题是 Job 类似乎与外部类明显是相当隔离的。
我确信有一个好方法可以做到这一点,但我还没有偶然发现它。
public class RestartJob : IJob
{
public RestartJob()
{
}
public virtual void Execute(IJobExecutionContext context)
{
//Send Restart EventHandler Subscription to Console.
}
}
I have a Console Application that instantiates a Quartz Scheduler.
I would like a Job to raise an event Handler so that the "Mother App" calls a particular Method.
The problem is that the Job Class seems to be pretty isolated to the external classes apparently.
I am sure there is a good way to do this but I did not stumble upon it yet.
public class RestartJob : IJob
{
public RestartJob()
{
}
public virtual void Execute(IJobExecutionContext context)
{
//Send Restart EventHandler Subscription to Console.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通过在包含调度程序逻辑的类上实现单例来解决我的问题。
很有魅力。希望这可以帮助其他人解决在我看来“必须具备”的功能。
用法 :
I solved my problem by implementing a singleton on the class containing the Scheduler Logic.
Works a charm. Hope this could help other to solve what seems to me as a "Must-Have" feature.
Usage :
您可以在 JobDataMap 中传递事件处理程序,然后使用作业中的事件处理程序。
创建工作时
在工作类别上:
You can pass the event handler within a JobDataMap and then use the event handler from your job.
When Creating your job
On your job class:
你可以试试这个:
创建 IJobDetail :
用法:
You can try this :
Create IJobDetail :
Usage :