Devo eseguire un'operazione lungo in un thread e continuare restituendo il risultato a una funzione. Qui è il mio codice:Timeout factory task C#
Task<ProductEventArgs>.Factory.StartNew(() =>
{
try
{
// long operation which return new ProductEventArgs with a list of product
}
catch (Exception e)
{
return new ProductEventArgs() { E = e };
}
}).ContinueWith((x) => handleResult(x.Result), TaskScheduler.FromCurrentSynchronizationContext());
Il problema è in realtà non ho un timeout. Voglio mettere un timer per restituire qualcosa del genere:
new ProductEventArgs() { E = new Exception("timeout") };
se il timeout è raggiunto. Non posso usare attendere/asincrare. Grazie mille!
Amore voi: - * Sono un po 'nuova su C# e più sulla gestione dei thread e si fanno il mio giorno! – Rototo