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?
3 Réponses
+ 2
Can you post a snippet of your code somewhere so I can understand better what your are actually doing? :)
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
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.