zoukankan      html  css  js  c++  java
  • C# loop executed one by one wait the former completed

    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!
    
    ");
                }
            }
    
            private static void PrintTime(int i)
            {
                Console.WriteLine($"i is {i},Now is {DateTime.Now.ToString("yyyyMMddHHmmssffff")}");
                Thread.Sleep(300);
            }
        }
    }
  • 相关阅读:
    SDUSTOJ 1466
    UVa
    51Nod
    UVa
    easyui-启用禁用方法
    设置系统时间
    移除/添加属性
    .net生成二维码图片
    Mysql数据库误删恢复
    js 加减乘除运算
  • 原文地址:https://www.cnblogs.com/Fred1987/p/11922716.html
Copyright © 2011-2022 走看看