Parallel Programming C # to get up early three things

story background

Reveals a yarn out of the sun, but also a Monday.

Take it easy

A look at the time, still early, then jumped up and tap

  • dressing
  • Brush teeth
  • Wash

With the code for, it should be this:

// Program.cs
using System;
using System.Diagnostics;
using System.Threading;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("begin...");
            Stopwatch sw = new Stopwatch();
            sw.Start();
            Dress();
            BrushTeeth();
            WashFace();
            sw.Stop();
            Console.WriteLine($"...end 耗时:{sw.Elapsed.Seconds} 秒");
            Console.ReadKey();
        }

        /// <summary>
        /// 穿衣
        /// </summary>
        static void Dress()
        {
            Thread.Sleep(timeout: TimeSpan.FromSeconds(value: 1));
        }

        /// <summary>
        /// 刷牙
        /// </summary>
        static void BrushTeeth()
        {
            Thread.Sleep(timeout: TimeSpan.FromSeconds(value: 3));
        }

        /// <summary>
        /// 洗脸
        /// </summary>
        static void WashFace()
        {
            Thread.Sleep(timeout: TimeSpan.FromSeconds(value: 5));
        }
    }
}

After running, wait for a while, you will see the following output:

begin...
...end 耗时:9 秒

Guess you like

Origin www.cnblogs.com/taadis/p/11112929.html