1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ProgramacaoParalela
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Pressione ENTER para iniciar");
Console.ReadLine();
// Invocar os métodos que vamos executar
Parallel.Invoke(
new Action(exibirCarros),
new Action(exibirFarol)
);
// Aguardar a continuação do programa
Console.WriteLine("\nO método Main foi encerrado. Tecle Enter");
Console.ReadLine();
}
static void exibirCarros()
{
string[] carrosArray = { "Ambulancia", "Bombeiros", "Policia", "Passeio" };
foreach (string carro in carrosArray)
{
Console.WriteLine("Carro: {0}", carro);
Thread.Sleep(100);
}
}
static void exibirFarol()
{
string[] farolArray = { "Verde", "Amarelo", "Vermelho" };
foreach (string farol in farolArray)
{
Console.WriteLine("Farol : {0}", farol);
Thread.Sleep(100);
}
}
}
}
In my code above, after the execution need the car "ride" take some preferred lighthouse the green lighthouse and in the execution of the code it does not get any lighthouse! for this code to keep repeating need a loop type o while, but when adding it in the code an error message appears, I need to call some class that has it or change some parameter of the code?