Created
April 25, 2012 08:04
-
-
Save masaru-b-cl/2488078 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Threading; | |
using System.Collections.Concurrent; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("Begin"); | |
var tasks = new[] | |
{ | |
Task.Factory.StartNew(() => { | |
Console.WriteLine("Task1 is running"); | |
Thread.Sleep(1000); | |
Console.WriteLine("Task1 is finished"); | |
}), | |
Task.Factory.StartNew(() => { | |
Console.WriteLine("Task2 is running"); | |
Thread.Sleep(2000); | |
Console.WriteLine("Task2 is finished"); | |
}), | |
Task.Factory.StartNew(() => { | |
Console.WriteLine("Task3 is running"); | |
Thread.Sleep(3000); | |
Console.WriteLine("Task3 is finished"); | |
}), | |
}; | |
var index = Task.WaitAny(tasks); | |
Console.WriteLine(index); | |
Console.WriteLine("End Any"); | |
Task.WaitAll(tasks); | |
Console.WriteLine("End All"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment