Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Console APP: How to run other codes based on the value of a variable, using a timer, wait a few minutes, check the variable and run again?

$
0
0

Hello my friends:

I am getting the row count from a database and assigning it to a variable. I need to run or call otherClasses and Methods from the Main Method of aConsole App based on the value assigned to the variable from the database.

Here are the steps:

  1. Check the variable, if it is greater than zero
  2. Run the code inside the main method
  3. Then wait for X seconds using timer
  4. After X seconds, check the variable again and if it is still greater than zero, run and wait again.
  5. Finally, if the variable is equals zero, exit the console.

What I do not know is how to repeat the wait and execute.

The following code i an example, however: I need the program to stop at each interval.

    static void Main(string[] args)
    {
        int intCheckRowCount = Database.DataExists();

        while (intCheckRowCount > 0)
        {
            intCheckRowCount = Database.DataExists();
            //Run Code Here
            //Then Wait
            Thread.Sleep(20000);
        }
    }

Viewing all articles
Browse latest Browse all 31927

Trending Articles