c# - ASP.Net MVC 4 I need to Delay execution -
i have asp.net mvc 4 application periodically calls external api information (resource). resource has rate limiter account (meaning other apps use same pool , may hit limit). when limit hit, send http status code 429 header of "retry-after" in seconds (lets 25 seconds).
if app gets response, need delay execution 25 seconds , retry. first off, let me method code running under asp.net 4.5 async method. this, thinking using system.threading.thread.sleep(25000)
now, don't use this, there better way of doing this?
i have apologize open ended question, couldn't find on proper way of delay execution (while keeping things async , making sure don't run out of threads)
update: following code better delay?
await task.run(() => thread.sleep(10000))
you shouldn't use thread.sleep
because blocks thread amount of time server less scalable. should instead use task.delay
waits asynchronously without blocking thread:
await task.delay(10000)
task.delay
uses timer
internally accomplish that. more info: thread.sleep vs task.delay?
Comments
Post a Comment