Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
retrylogic
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); // int retryCount = 1; { TimeSpan MinBackoff = TimeSpan.FromSeconds(1); TimeSpan MaxBackoff = TimeSpan.FromSeconds(30); TimeSpan DeltaBackoff = TimeSpan.FromSeconds(10); var random = new Random(); TimeSpan total = TimeSpan.FromSeconds(0); for(int retryCount= 0; retryCount <5 ; retryCount++){ var delta = (long)((Math.Pow(2.0, retryCount) - 1.0) * random.Next((int)(DeltaBackoff.TotalMilliseconds * 0.8), (int)(DeltaBackoff.TotalMilliseconds * 1.2))); //if the delta is negative (data type overflow), set interval to max backoff, else set it to the min of max and min+delta var interval = (delta < 0) ? (long) MaxBackoff.TotalMilliseconds : (long) Math.Min(checked(MinBackoff.TotalMilliseconds + delta), MaxBackoff.TotalMilliseconds); Console.WriteLine("interation count"+ retryCount + " ==" +TimeSpan.FromMilliseconds(interval)); total = total + TimeSpan.FromMilliseconds(interval); } Console.WriteLine(total); } { TimeSpan MinBackoff2 = TimeSpan.FromSeconds(1); TimeSpan MaxBackoff2 = TimeSpan.FromSeconds(180); TimeSpan DeltaBackoff2 = TimeSpan.FromSeconds(15); var random2 = new Random(); TimeSpan total2 = TimeSpan.FromSeconds(0); for(int retryCount= 0; retryCount <5 ; retryCount++){ var delta = (long)((Math.Pow(2.0, retryCount) - 1.0) * random2.Next((int)(DeltaBackoff2.TotalMilliseconds * 0.8), (int)(DeltaBackoff2.TotalMilliseconds * 1.2))); //if the delta is negative (data type overflow), set interval to max backoff, else set it to the min of max and min+delta var interval = (delta < 0) ? (long) MaxBackoff2.TotalMilliseconds : (long) Math.Min(checked(MinBackoff2.TotalMilliseconds + delta), MaxBackoff2.TotalMilliseconds); Console.WriteLine("interation count"+ retryCount + " ==" +TimeSpan.FromMilliseconds(interval)); total2 = total2 + TimeSpan.FromMilliseconds(interval); } Console.WriteLine(total2); } } } }
run
|
edit
|
history
|
help
0
borrar_xml_tags_vacios
c#
hola1
Stacks: Balanced Brackets
Dan's Dice
services
Intuit // C# // listing_4.7 (case // calculator)
barcos
2.10.4
4.2 Casting