Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created April 25, 2012 08:04
Show Gist options
  • Save masaru-b-cl/2488078 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/2488078 to your computer and use it in GitHub Desktop.
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