Instead of looping around basically, you can use a timer. Basically you have to set up a timer, and then you can just wait on the Console.Readline () console so that the console does not close.
Edit - here is an example
using System; namespace ConsoleApplication1 { class Program { private const int MilliSecondsToWait = 30000; private static System.Timers.Timer EmailTimer; static void Main(string[] args) { EmailTimer = new System.Timers.Timer(MilliSecondsToWait); EmailTimer.Elapsed += EmailTimer_Elapsed; EmailTimer.Start(); Console.WriteLine("Press Enter to quit."); Console.ReadLine();
using System; namespace ConsoleApplication1 { class Program { private const int MilliSecondsToWait = 30000; private static System.Timers.Timer EmailTimer; static void Main(string[] args) { EmailTimer = new System.Timers.Timer(MilliSecondsToWait); EmailTimer.Elapsed += EmailTimer_Elapsed; EmailTimer.Start(); Console.WriteLine("Press Enter to quit."); Console.ReadLine();
source share