150
1
using System;
2
using System.Threading;
3
using System.Threading.Tasks;
4
using System.Collections.Generic;
5
using System.Net.NetworkInformation;
6
7
public class Program
8
{
9
private static int failed = 0;
10
11
public static void Main()
12
{
13
//WaitForTaskWithTimeout();
14
//WaitAllForTasks();
15
//WaitForAnyTask();
16
WhenAllForTasks();
17
WhenAnyForTasks();
18
}
19
20
private static void WaitForTaskWithTimeout()
21
{
22
Task taskA = Task.Run(() => DoComputation());
23
// use < 50 for timeout interval
24
if(!taskA.Wait(100))
Cached Result
Url www.websitenotfound2.com, Thread Id: 6, Status: An exception occurred during a Ping request.
Url www.websitenotfound1.com, Thread Id: 4, Status: An exception occurred during a Ping request.
2 tasks failed
Any task completed
Url www.websitenotfound1.com, Thread Id: 4, Status: An exception occurred during a Ping request.
2 tasks failed
Any task completed