|
1 | 1 | ---
|
2 | 2 | title: Avoid getting throttled or blocked in SharePoint Online
|
3 | 3 | description: Find out about throttling in SharePoint Online, and learn how to avoid being throttled or blocked. Includes sample client-side object model (CSOM) and REST code you can use to make your task easier.
|
4 |
| -ms.date: 07/07/2021 |
| 4 | +ms.date: 05/11/2022 |
5 | 5 | ms.prod: sharepoint
|
6 | 6 | ms.assetid: 33ed8106-d850-42b1-8d7f-5ba83901149c
|
7 | 7 | ms.localizationpriority: high
|
@@ -183,17 +183,16 @@ HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse(
|
183 | 183 | Add this extension method in a static class and use `ExecuteQueryWithIncrementalRetry` instead of `ExecuteQuery` to make your code handle throttling requests.
|
184 | 184 |
|
185 | 185 | ```csharp
|
186 |
| -public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientContext, int retryCount, int delay) |
| 186 | +public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientContext, int retryCount) |
187 | 187 | {
|
188 | 188 | int retryAttempts = 0;
|
189 |
| - int backoffInterval = delay; |
190 | 189 | int retryAfterInterval = 0;
|
191 | 190 | bool retry = false;
|
192 | 191 | ClientRequestWrapper wrapper = null;
|
193 | 192 | if (retryCount <= 0)
|
| 193 | + { |
194 | 194 | throw new ArgumentException("Provide a retry count greater than zero.");
|
195 |
| - if (delay <= 0) |
196 |
| - throw new ArgumentException("Provide a delay greater than zero."); |
| 195 | + } |
197 | 196 |
|
198 | 197 | // Do while retry attempt is less than retry count
|
199 | 198 | while (retryAttempts < retryCount)
|
@@ -234,25 +233,11 @@ public static void ExecuteQueryWithIncrementalRetry(this ClientContext clientCon
|
234 | 233 | wrapper = (ClientRequestWrapper)ex.Data["ClientRequest"];
|
235 | 234 | retry = true;
|
236 | 235 |
|
237 |
| - // Determine the retry after value - use the `Retry-After` header when available |
238 |
| - string retryAfterHeader = response.GetResponseHeader("Retry-After"); |
239 |
| - if (!string.IsNullOrEmpty(retryAfterHeader)) |
240 |
| - { |
241 |
| - if (!Int32.TryParse(retryAfterHeader, out retryAfterInterval)) |
242 |
| - { |
243 |
| - retryAfterInterval = backoffInterval; |
244 |
| - } |
245 |
| - } |
246 |
| - else |
247 |
| - { |
248 |
| - retryAfterInterval = backoffInterval; |
249 |
| - } |
| 236 | + // Determine the retry after value - use the `Retry-After` header |
| 237 | + retryAfterInterval = Int32.Parse(response.GetResponseHeader("Retry-After")); |
250 | 238 |
|
251 | 239 | // Delay for the requested seconds
|
252 | 240 | Thread.Sleep(retryAfterInterval * 1000);
|
253 |
| - |
254 |
| - // Increase counters |
255 |
| - backoffInterval = backoffInterval * 2; |
256 | 241 | }
|
257 | 242 | else
|
258 | 243 | {
|
|
0 commit comments