如何使 Quartz.net 作业在单线程单元中运行?
我只是尝试了这个:
public class FooJob : IJob
{
public FooJob() { }
public void Execute(JobExecutionContext context)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
}
}
但它产生了 InvalidOperationException。有想法吗?
I simply tried this:
public class FooJob : IJob
{
public FooJob() { }
public void Execute(JobExecutionContext context)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
}
}
But it produces InvalidOperationException. Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该线程已从线程池中分配,因此它不能成为 STA 中创建的线程。您可以做的是从 IJob.Execute 方法启动 STA 线程。
The thread has already been allocated from the thread pool so it can't become a thread created in an STA. What you can do is launch an STA thread from your IJob.Execute method.