-
Notifications
You must be signed in to change notification settings - Fork 58
/
Program.cs
60 lines (47 loc) · 1.83 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#region Copyright (c) 2004-2010 by SharpCrafters s.r.o.
// This file is part of PostSharp source code and is the property of SharpCrafters s.r.o.
//
// Source code is provided to customers under strict non-disclosure agreement (NDA).
// YOU MUST HAVE READ THE NDA BEFORE HAVING RECEIVED ACCESS TO THIS SOURCE CODE.
// Severe financial penalties apply in case of non respect of the NDA.
#endregion
using System;
using System.Linq;
using System.Threading.Tasks;
namespace PostSharp.Samples.Threading.PingPong
{
internal class Program
{
private static void Main()
{
AsyncMain().Wait();
}
private static async Task AsyncMain()
{
// Create a logger;
var consoleLogger = new ConsoleLogger();
// Create two players.
var trump = new Player(consoleLogger, "Trump", 0.92);
var clinton = new Player(consoleLogger, "Clinton", 0.9);
// Start several concurrent games between players.
ConsoleColor[] colors =
{
ConsoleColor.Cyan, ConsoleColor.Blue, ConsoleColor.Green, ConsoleColor.Magenta, ConsoleColor.Yellow,
ConsoleColor.Red
};
var games = colors.Select(color => trump.Ping(clinton, color)).ToArray();
// Wait for all games to finish.
await Task.WhenAll(games);
consoleLogger.WriteLine("We are all done");
// Display winner and stats.
for (var i = 0; i < games.Length; i++)
{
consoleLogger.WriteLine(string.Format("Winner for game {0}: {1}", colors[i], games[i].Result), colors[i]);
}
consoleLogger.WriteLine(string.Format("{0} totally received {1} balls", trump, await trump.GetCounter()));
consoleLogger.WriteLine(string.Format("{0} totally received {1} balls", clinton, await clinton.GetCounter()));
// Wait for the console logger.
await consoleLogger.Flush();
}
}
}