Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- using System.Collections.Generic;
- class Program {
- private void WriteABunchOfStuff(int id){
- int j=0;
- for (int i=0; i<50; i++){
- Console.WriteLine("{0}# task here!", id);
- j++;
- }
- }
- public async Task Run(){
- List<Task> tasks = new();
- for (int i=0; i<10; i++){
- var tmp=i;
- tasks.Add(Task.Run(()=>{WriteABunchOfStuff(tmp); Console.WriteLine("{0} Done", tmp);}));
- }
- await Task.WhenAll(tasks);
- Console.WriteLine("Done");
- }
- public static async Task Main(){
- var p = new Program();
- await p.Run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement