I have a do/while like the following:
do {
//1.look for a report
//2.either use interops to run an xl macro report or run a batch file report or run vbs file report
//3.then sleep/pause program for 150seconds
} while (look for next report to run)
This is all withing a Console application.
How do I create the 150 second pause/sleep ? Step 2 might involve running various processes and I’m slightly worried that simply using Thread.Sleep might be troublesome as it is not thread safe.
Should I somehow work this sort of code into the structure i.e. put steps 1 and 2 in the CallMeBack method?
static void Main(string[] args) {
var t = new System.Timers.Timer(1000);
t.Elapsed += (s, e) => CallMeBack();
t.Start();
Console.ReadLine();
}
public static void CallMeBack() {
//1.look for a report
//2.either use interops to run an xl macro report or run a batch file report or run vbs file report
Console.WriteLine("Doing some consuming time work using sleep");
}
(the above is taken from HERE)
This works in millisecond, you can catch it in case it gets interrupted, but that usually does not happen.
Edit:
Another option is to use join if you simply want to wait till others are done or if you want to execute once every 150 seconds, your own answer would work. Make sure you know what you want before asking.
If you want thread-safe pause use: