Guest User

Untitled

a guest
Jun 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. static Semaphore requestLimiter = new Semaphore(500, 500);
  2.  
  3. ...
  4.  
  5. String GetResultFromAPI() {
  6. if (!requestLimiter.WaitOne(0)) return null;
  7.  
  8. try
  9. {
  10. // ... code to perform API call, with a timeout specified on the HttpWebRequest
  11. return result;
  12. } catch { /* ignore exceptions */ }
  13. finally
  14. {
  15. requestLimiter.Release();
  16. }
  17. return null;
  18. }
Add Comment
Please, Sign In to add comment