static object _Invoke(string path, bool sendLang, IDictionary <string, object> args, IDictionary <string, object> payload, Func <object, object> fixupResult, Func <object, object> fixupError, string httpMethod) { var url = _apiUrlBase; if (!path.StartsWith("/")) { url = string.Concat(url, "/"); } url = string.Concat(url, path); if (null == args) { args = new JsonObject(); } args["api_key"] = ApiKey; if (sendLang && !string.IsNullOrEmpty(Language)) { args["language"] = Language; } object result = null; var retryCount = 0; while (null == result) { ++retryCount; try { var s = JsonRpc.GetInvocationUrl(url, args); System.Diagnostics.Debug.WriteLine("Requesting from " + s); result = JsonRpc.Invoke(s, null /*we already computed the url*/, payload, null, httpMethod, fixupResult, fixupError, Tmdb.CacheLevel); if (null == result) { break; } } catch (JsonRpcException rex) { if (retryCount > 11) { rex.Json.Add("retry_count_exceeded:", retryCount - 1); throw; } // are we over the request limit? if (25 == rex.ErrorCode) { System.Diagnostics.Debug.WriteLine(rex.Message + ".. throttling " + url); // wait and try again Thread.Sleep(RequestThrottleDelay); } else if (-39 == rex.ErrorCode) { continue; //malformed or empty json, try again } else { throw; } } } return(result); }