たすく

using System; using System.Threading; using System.Thre […]

using System; using System.Threading; using System.Thre […]

  • タグ:
  • タグはありません
using System;
using System.Threading;
using System.Threading.Tasks;

class Program{
	static Action<Action,int> setTimeout=(fn,s)=>Task.Delay(s).ContinueWith(t=>fn());

	static void Main(){
		void recur(int i=1){
			setTimeout(()=>{
				Console.WriteLine($"{i}s recur");
				if(i<10) recur(i+1);
			},1000);
		}
		Task.Run(()=>recur()).Wait();

		new Func<Task>(async()=>{
			for(int i=1;i<=10;i++){
				await Task.Delay(1000);
				Console.WriteLine($"{i}s async");
			}
		})().Wait();
	}
}