using System;
using System.Threading.Tasks;
using System.Threading;

namespace Syslab.Sample.Ex04
{
    class Program
    {
        static object lockObj = new object();
        static int counter = 1;

        static void Main(string[] args)
        {
            Parallel.Invoke(() => { DoSomeWork(1000); }, () => { DoSomeWork(500); }, () => { DoSomeWork(100); });
        }

        static void DoSomeWork(int sleep)
        {
            int assignedTaskNumber;
            lock (lockObj) { assignedTaskNumber = counter++; }

            Console.WriteLine(string.Format("Começando a tarefa número [{0}], aguardando {1} ms.", assignedTaskNumber, sleep));
            Thread.Sleep(sleep);
            Console.WriteLine(string.Format("Terminando a tarefa número [{0}], aguardando {1} ms.", assignedTaskNumber, sleep));
        }
    }
}
