public FreeProxy GetFreeProxy(bool dequeue = true) { if (FreeProxies == null) { return(null); } if (!dequeue) { var idx = CodeKit.RandomNumber(0, FreeProxies.Count); return(FreeProxies.ToList()[idx]); } else { var proxy = FreeProxies.Dequeue(); return(proxy); } }
public static void LoopAction(Func <bool> loopAction, ref Exception exceptionThrown, bool exitWhenActionIsTrue, int iterationLimit = 0, int iterationTimeout = 5000) { if (loopAction == null) { return; } var itr = 0; while (true) { try { if (iterationLimit > 0 && itr >= iterationLimit) { break; } else { itr++; } var result = loopAction(); if (exitWhenActionIsTrue && result) { break; } CodeKit.Delay(iterationTimeout); } catch (Exception ex) { exceptionThrown = ex; break; } } }
public static bool Retry(Func <bool> retryAction, ref Exception finalExceptionThrown, int maxretry = 5, int iterationTimeout = 5000) { if (retryAction == null) { return(false); } for (var ctr = 0; ctr < maxretry; ctr++) { try { if (retryAction()) { finalExceptionThrown = null; return(true); } } catch (Exception ex) { finalExceptionThrown = ex; } CodeKit.Delay2(iterationTimeout); } return(false); }