My program lags the computer because i have it going through a while loop to continue check if a condition is true. Is there any way i can have a wait for user input such as pressing a key to perform the evaluation.

Or is there any way to have nothing running and as soon as the condition evaluates to true it will do what i want? Like when you click a button on a form, nothing happens and its in wait mode untill that specific action happens and then it jumps into a method. Can i have something such as comparison conditioning to true and be noticed without having to constantly check it and then it would take me into a method such as a button click?

Id rather the second one, but if not possible the first will do just as good.

Edited 6 Years Ago by Steve_Jones: n/a

Ofcourse there is, go to the statement whichever you want to debug and press F9 and a red button will appear (you can click there to activate/deactivate that aswell, and if you click on that with the right-button you can select any of the options you listed above, feel free to explore. When you run the program it will stop at that BREAKPOINT and you can analyse the variables. If you have more question feel free to ask here :)

Another way of doing this; is by clicking in the leftmost column of a code listing.
A brownish ball will appear and your program will stop there if it is run. You have set a BREAKPOINT! If your program does not stop there, you know that part of your program code is not executed. You can set more breakpoints if you want to do so.

There are several ways of handling this. One is to attach a handler to the Application.Idle event. This event triggers when your application goes idle.

Another is set a timer and in the trigger event check your condition.

You can also put your check condition on another thread.

Well im not talking about for debugging, im talking about actual part of application. Unless you mean i can use the breakpoint as part of coding and then code something else to restart it. If i loop back it will stop at the breakpoint again?

@Momerath: So your saying delay the condition check to less frequent checks instead of the maximum it can process like it will be doing by default? The first part: I can set the time until idle? The second part: If you want to, teach me how to use timers, but thats just a request i can look for myself also. The third part: Put my check condition in another thread? Im not sure what you mean.

Thank you all very much for your responses.

Application.Idle triggers whenever your application is doing nothing. For example, when your Form is waiting on the user to input something, press a button, etc. it will trigger.

Here is an example of a timer:

public static void Main() {
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
    // Set the Interval to 5 seconds.
    aTimer.Interval=5000;
    aTimer.Enabled=true;
 
    Console.WriteLine("Press \'q\' to quit the sample.");
    while(Console.Read()!='q');
}
 
// Specify what you want to happen when the Elapsed event is raised.
private static void OnTimedEvent(object source, ElapsedEventArgs e) {
    Console.WriteLine("Hello World!");
}

This will display "Hello World!" every 5 seconds until you press q to end it.

I'm not sure threading will help much with the problem you are having. Without knowing more about what condition you are waiting for and what triggers the condition.

This question has already been answered. Start a new discussion instead.