Thread.Sleep in Asp.net vNext

I need to make a call to a JSON api which only allows a limited number of requests per second to ensure no DDOS is happening from a specific IP. It doesn't matter how long the requests take, as this will be done as an automated process overnight, however I need some way of pausing between each request to ensure my IP isn't temporarily blacklisted.

Now before I would of done Thread.Sleep(1000) to ensure only 1 request a second is sent, but in asp.net vNext Thread.Sleep doesn't work/exist so I cannot do this.

Is there an alternative or better way to handle what I need to do? There is no bulk API so it has to be done 1 request at a time.

Thanks in advance.

Jon Skeet
people
quotationmark

You're missing a dependency. If your code is not async, you shouldn't use Task.Delay... you should use Thread.Sleep() or normal.

Just add the following dependency:

"System.Threading.Thread": "4.0.0-beta-23516"

Then you can use Thread.Sleep as normal.

Of course, if you are writing async code, then await Task.Delay(...) is appropriate - again, just like normal.

people

See more on this question at Stackoverflow