c# - System.Threading.Task does not contain definition -
i cant have .delay definition on system.threading.task.
public async task<string> waitasynchronouslyasync() { await task.delay(10000); return "finished"; }
you using .net 4. then, there no task.delay
. however, there library microsoft called microsoft.bcl.async, , provides alternative: taskex.delay
.
it used this:
public async task<string> waitasynchronouslyasync() { await taskex.delay(10000); return "finished"; }
your other options either update .net 4.5, or implement yourself:
public static task delay(double milliseconds) { var tcs = new taskcompletionsource<bool>(); system.timers.timer timer = new system.timers.timer(); timer.elapsed += (o, e) => tcs.trysetresult(true); timer.interval = milliseconds; timer.autoreset = false; timer.start(); return tcs.task; }
(taken servy's answer here).
Comments
Post a Comment