https://www.youtube.com/watch?v=VZq7PqlUbyI&list=PLO56HZSjrPTB4NxAsEP8HRk6YKBDLbp7m&index=78
using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            WriteLine("요리 종료");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            void Egg()
            {
                Thread.Sleep(3000);
                WriteLine("달걀 3초");
            }
            Egg();
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            void Egg()
            {
                Thread.Sleep(3000);
                WriteLine("달걀 3초");
            }
            Egg();
            void Souap()
            {
                Thread.Sleep(5000);
                WriteLine("국 5초");
            }
            Souap();
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            void Egg()
            {
                Thread.Sleep(3000);
                WriteLine("달걀 3초");
            }
            Egg();
            void Souap()
            {
                Thread.Sleep(5000);
                WriteLine("국 5초");
            }
            Souap();
            void Rice()
            {
                Thread.Sleep(7000);
                WriteLine("국 5초");
            }
            Rice();
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}

using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            void Egg()
            {
                Thread.Sleep(3000);
                WriteLine("달걀 3초");
            }
            // Egg();
            Thread t1 = new Thread(new ThreadStart(Egg)); // ThreadStart, 대리자
            void Souap()
            {
                Thread.Sleep(5000);
                WriteLine("국 5초");
            }
            // Souap();
            Thread t2 = new Thread(Souap); // 대리 실행
            /*
            void Rice()
            {
                Thread.Sleep(7000);
                WriteLine("밥 7초");
            }
            Rice();
            */
            Thread t3 = new Thread(() =>
            {
                Thread.Sleep(7000);
                WriteLine("밥 7초");
            }); // ThreadStart, 대리자
            // async, 각자 비동기로 실행
            t1.Start(); 
            t2.Start();
            t3.Start();
            // await, 끝날 때 까지 대기
            t1.Join(); 
            t2.Join();
            t3.Join();
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}


using System;
using static System.Console;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
namespace testProject
{
    class Restrant
    {
        public void MakeFood()
        {
            WriteLine("요리 시작");
            DateTime start = DateTime.Now;
            void Egg()
            {
                Thread.Sleep(3000);
                WriteLine("달걀 3초");
            }
            // Egg();
            Thread t1 = new Thread(new ThreadStart(Egg)); // ThreadStart, 대리자
            void Souap()
            {
                Thread.Sleep(5000);
                WriteLine("국 5초");
            }
            // Souap();
            Thread t2 = new Thread(Souap); // 대리 실행
            /*
            void Rice()
            {
                Thread.Sleep(7000);
                WriteLine("밥 7초");
            }
            Rice();
            */
            Thread t3 = new Thread(() =>
            {
                Thread.Sleep(7000);
                WriteLine("밥 7초");
            }); // ThreadStart, 대리자
            // async, 각자 비동기로 실행
            t1.Start(); 
            t2.Start();
            t3.Start();
            // await, 끝날 때 까지 대기
            t1.Join(); 
            t2.Join();
            t3.Join();
            WriteLine($"요리 종료 : {(DateTime.Now - start).TotalSeconds}");
            WriteLine("식사 시작");
            SingleProc(); // 단일 CPU
            MultiProc();  // 멀티 CPU
            WriteLine($"식사 종료 : {(DateTime.Now - start).TotalSeconds}");
        }
        private void SingleProc()
        {
            for (int i = 0; i < 20_000; i++)
            {
                WriteLine("수다");
            }
        }
        private void MultiProc()
        {
            // Parallel, 병렬처리
            Parallel.For(0, 20_000, (i) => { WriteLine("수다"); });
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            (new Restrant()).MakeFood();
        }
    }
}


