52
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
var vm = VoteMachine.Instance;
13
vm.RegisterVote();
14
});
15
Console.WriteLine(VoteMachine.Instance.TotalVotes);
16
}
17
}
18
19
public class VoteMachine
20
{
21
private static readonly VoteMachine _instance = new VoteMachine();
22
private int _totalVotes = 0;
23
static VoteMachine()
24
{
Cached Result