using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;

namespace Syslab.Sample.Ex08
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            
            Task task1 = Task.Factory.StartNew(() => { DisplayTime(); });
            Task task2 = Task.Factory.StartNew(() => { WriteTextOnConsole(); });

            Console.ReadKey();
        }

        static void DisplayTime()
        {
            while (Thread.CurrentThread.IsAlive)
            {
                string time = DateTime.Now.ToString("hh:mm:ss");
                Console.SetCursorPosition(0, 0);
                Console.Write(time);
                Thread.Sleep(1000);
            }
        }

        static void WriteTextOnConsole()
        {
            char[] text = "Enquanto um objeto do tipo Task apresenta a hora o outro escreve um texto.".ToArray<char>();

            for (int i = 0; i < text.Length; i++)
            {
                Console.SetCursorPosition(i, 3);
                Console.Write(text[i]);
                Thread.Sleep(100);
            }
        }
    }
}


