59
1
using System;
2
using System.Linq;
3
using System.Threading.Tasks;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
var numbers = Enumerable.Range(0, 10);
10
Parallel.ForEach(numbers, i =>
11
{
12
//Console.WriteLine("Task {0}:", i);
13
var vm = VoteMachine.Instance;
14
vm.RegisterVote();
15
});
16
Console.WriteLine("Total Votes: {0}", VoteMachine.Instance.TotalVote);
17
}
18
}
19
20
public class VoteMachine
21
{
22
private static VoteMachine _instance = null;
23
private int _totalVote = 0;
24
private static readonly object padlock = new object ();
Cached Result