J'utilise Watin à l'intérieur des tâches qui jettent exceptionWatin avec System.Threading.Tasks.Task jeter ThreadStateException
ThreadStateException with an error message of 'The CurrentThread needs to have its ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer'
Mon code ressemble
Task task = Task.Factory.StartNew(() =>
{
try{
string Url="www.google.com";
IE ie = new IE(Url);
}
catch (Exception ex)
{
throw ex; //ThreadStateException
}
});
Comment puis-je résoudre ce problème?
J'essaye de google mais incapable de trouver la solution.
Si vous vous souciez du type de thread sur lequel la tâche doit s'exécuter, vous devriez peut-être simplement créer un thread à la place. Vous pouvez l'inclure dans une méthode qui utilise 'TaskCompletionSource' pour exposer une' Task'. Voir http://stackoverflow.com/a/16722767/1726343 –