C# loop executed one by one wait the former completed
程序员文章站
2022-04-09 15:00:28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ... ......
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); } } }
下一篇: $和jquery的关系