public static void QueryBeforeExecute(object sender, Tweetinvi.Events.QueryBeforeExecuteEventArgs args) { var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL); // Some methods are not RateLimited. Invoking such a method will result in the queryRateLimits to be null if (queryRateLimits != null) { if (queryRateLimits.Remaining > 0) { // We have enough resource to execute the query return; } // Strategy #1 : Wait for RateLimits to be available Console.WriteLine("Waiting for RateLimits until : {0}", queryRateLimits.ResetDateTime.ToLongTimeString()); args.Cancel = true; } }
public static void RateLimitCheck(object sender, Tweetinvi.Events.QueryBeforeExecuteEventArgs args) { var queryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL); if (queryRateLimits == null) { // Some methods are not RateLimited. Invoking such a method will result in the queryRateLimits to be null return; } if (queryRateLimits.Remaining == 0) { Console.WriteLine("Insufficient rate limit for " + args.QueryURL + " cancelling query"); args.Cancel = true; return; } float remainingPercent = (float)queryRateLimits.Remaining / queryRateLimits.Limit; if (remainingPercent < 0.5f) { Console.WriteLine("Approaching rate limit for " + args.QueryURL + " Remaining: " + queryRateLimits.Remaining); } }