Esempio n. 1
0
        public async static Task <Account> Process()
        {
            var account = new Account(1000);
            var tasks   = new Task[100];

            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = Task.Run(() => AccountTest.Update(account));
            }
            await Task.WhenAll(tasks);

            return(account);
        }
Esempio n. 2
0
        public async Task Main()
        {
            var account = new Account(1000);
            var tasks   = new Task[100];

            for (int i = 0; i < tasks.Length; i++)
            {
                tasks[i] = Task.Run(() => AccountTest.Update(account));
            }
            await Task.WhenAll(tasks);

            Console.WriteLine($"Account balance {account.GetBalance()}");
            Console.WriteLine($"The same acoount balance {(await AccountTest.Process()).GetBalance()}");
        }