Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Semaphore requestLimiter = new Semaphore(500, 500);
- ...
- String GetResultFromAPI() {
- if (!requestLimiter.WaitOne(0)) return null;
- try
- {
- // ... code to perform API call, with a timeout specified on the HttpWebRequest
- return result;
- } catch { /* ignore exceptions */ }
- finally
- {
- requestLimiter.Release();
- }
- return null;
- }
Add Comment
Please, Sign In to add comment