كيفية جعل وظيفة Quartz.net لتشغيلها في شقة واحدة الخيوط؟
-
11-09-2019 - |
سؤال
حاولت ببساطة هذا:
public class FooJob : IJob
{
public FooJob() { }
public void Execute(JobExecutionContext context)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
}
}
لكنها تنتج InvalistoperationException. الأفكار؟
المحلول
تم تخصيص مؤشر الترابط بالفعل من تجمع الخيط حتى لا يمكن أن يصبح مؤشر ترابط تم إنشاؤه في STA. ما يمكنك القيام به هو إطلاق مؤشر ترابط STA من طريقة iJob.Execute الخاصة بك.
public void Execute(JobExecutionContext context)
{
Thread t= new Thread(DoSomeWork);
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
لا تنتمي إلى StackOverflow