giovedì 20 dicembre 2012

Controllo del timeout su un Task

Ci sono molti modi per verificare se l'esecuzione di un task si conclude entro un periodo di timeout. Questo è il più semplice ma non per questo meno efficace:
using System.Threading.Tasks;

[...]

try
{
    Task executeTask = STask.Factory.StartNew(() => DoSomething());

    //Wait for 5 minutes
    int index = System.Threading.Tasks.Task.WaitAny(new[] { executeTask },
     TimeSpan.FromSeconds(300));

    if (index == -1)
    {
        //Task execution Time Out
    }
    else
    {
        //Task executed in-time
    }
}
catch (AggregateException aex)
{
    foreach (Exception ex in aex.InnerExceptions)
        LogError(ex, ex.Message);
}
catch (Exception ex)
{
    LogError(ex, "Error");
}

1 commento:

3om9n6kurn ha detto...

I lately got Pheatus Rapido which is already a excessive flow hotend. The factor is that additionally they promote the Rapido in an Ultra High Flow variant, and from the pictures, I found online, I wasn’t really sure how both variations differ. The strategy is intelligent and permits you to swap between High Flow and Ultra High Flow with none hassle. For the Ultra Manicure Kits High Flow, they don’t really make the heater longer however merely use a Volcano size nozzle and a special nut produced from nickel-plated copper to help conduct the heat down the nozzle.