Avoiding TimeoutException in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Avoiding TimeoutException in C#

I'm currently taking part in a challenge where I run through 1000 iterations of an equation, but keep bumping into TimeoutException, anyone know a workaround?

30th Jan 2017, 11:03 AM
Aaron
Aaron - avatar
3 Answers
+ 2
Can you post a snippet of your code somewhere so I can understand better what your are actually doing? :)
30th Jan 2017, 11:17 AM
Alex
Alex - avatar
0
I'm on mobile currently, but I'll try; int num = 1, iter = 1000; long sum=0, i = //Some 9 digit number, M = // Some 9 digit number; while (num <= iter){ sum+=(i%M); num++; if(num == iter){return sum;} } Note, each iteration has randomly generated 9 digit numbers
30th Jan 2017, 11:23 AM
Aaron
Aaron - avatar
0
Doesn't seem to be any issue on my end, hard to tell but a ugly workaround is to put it inside a try catch and ignore the exceptions, as an example. for (var x = 0; x < 1000; x++) { try { int num, iter = 1000; long sum=0, i = //Some 9 digit number, M = // Some 9 digit number; while (num <= iter){ sum+=(i%M); num++; if(num == iter){return sum;} } catch { // nothanks.jpg we leave this open with a comment } } Also, putting it inside it's own background worker or thread would be wise.
30th Jan 2017, 11:39 AM
Alex
Alex - avatar