I would like to create a program to act on multiple threads in a process, leaving it faster, that is, the threads working together to finish the service faster. But each one works individually in the process.
Sample code:
class Program
{
static void Main(string[] args)
{
Soma s = new Soma();
Thread[] Threads = new Thread[5];
for (int i = 0; i < 5; i++)
{
Threads[i] = new Thread(new ThreadStart(s.PrintNumbers));
}
foreach (Thread t in Threads)
t.Start();
Console.ReadLine();
}
}
class Soma
{
double soma = 0;
public void PrintNumbers()
{
for (int i = 0; i < 5; i++)
{
if (i%2 != 0)
{
soma -= i;
}
else
{
soma += i;
}
}
Console.WriteLine(soma);
}
}