Olá!
Prezados, fiz um programa com threads, mas o obetivo é fazer ele “erroneamente”.
Estou fazendo 20 usuários depositarem em uma conta bancária R$ 1.000 porém o saldo não pode chegar a R$ 20.000.
Eu programei da seguinte maneira.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SystemThreading;
namespace Program
{
class Program
{
static int val = 0;
static void saldo ()
{
for (int i = 0; i < 1000; i++)
{
val += 1;
Console.WriteLine("Thread: " + val);
}
}
static void Main (String [] args)
{
for (int i = 0; i < 20; i++)
{
Thread t = new Thread(saldo);
t.Start();
}
Console.WriteLine("\nSeu saldo é: " + val);
Console.ReadKey();
}
}
}
Alguém poderia me ajudar? Preciso que esta implementação não chegue a 20.000 o saldo total, teria que chegar por exemplo à: 19.998.
Grato a todos!
Rafael Vargas