0

I am trying to do a very large recursive operation, but it just hangs up. IS there any way of pausing t for some time, then make it continue?

Thanks in advance.

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by nickguletskii
1

This System.Threading.Thread.Sleep(100); makes your code to wait for 100 ms. But it doesn't yield CPU time to other threads if that's what you want. Use Application.DoEvents(); to yield some CPU time to other threads as well.

You may also use both together:

Application.DoEvents();
System.Threading.Thread.Sleep(100);

but I would try to avoid recursion in the first place and use BackgroundWorker if possible.

HTH

0

Every recursive operation has to have some kind of stopping condition.
If not, you can create a stack overflow or some other error.
Look at the classic example of the factorial calculation:

uint factorial(unint n) 
 {
     if (n <= 1) {
          return 1; // stopping condition
     } else {
          return n * factorial(n-1);
     }
 }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.