C# loop executed one by one wait the former completed

2022-10-13,,,

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.threading;
using system.threading.tasks;

namespace consoleapp393
{
    class program
    {
        static void main(string[] args)
        {
            loopcompleteddemo();
            console.readline();
        }

        static void loopcompleteddemo()
        {
            for(int i=0;i<10;i++)
            {
                task task = task.run(() =>
                {
                    printtime(i);
                });
                task.wait();
                console.writeline($"loop {i} completed!\n\n");
            }
        }

        private static void printtime(int i)
        {
            console.writeline($"i is {i},now is {datetime.now.tostring("yyyymmddhhmmssffff")}");
            thread.sleep(300);
        }
    }
}

 

《C# loop executed one by one wait the former completed.doc》

下载本文的Word格式文档,以方便收藏与打印。