Comment faire Quartz.net travail à exécuter dans un seul thread?
-
11-09-2019 - |
Question
J'ai simplement essayé ceci:
public class FooJob : IJob
{
public FooJob() { }
public void Execute(JobExecutionContext context)
{
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
}
}
Mais il produit InvalidOperationException. Idées?
La solution
Le fil a déjà été attribué à partir du pool de threads ne peut donc pas devenir un thread créé dans un STA. Ce que vous pouvez faire est de lancer un thread STA à partir de votre méthode IJob.Execute.
public void Execute(JobExecutionContext context)
{
Thread t= new Thread(DoSomeWork);
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow