I've created a C# console application and changed the output type to a Windows Application in Project > Project Properties to create a hidden program.
My main method looks like this:
static void Main(string[] args)
{
System.Timers.Timer timer = new System.Timers.Timer(); // Initialize a timer
timer.Elapsed += new System.Timers.ElapsedEventHandler(runProgram); // to call method runProgram
timer.Interval = 10000; // every 10 seconds
timer.AutoReset = true; // which auto-resets
timer.Enabled = true; // Enable timer
timer.Start(); // Start timer
Console.ReadLine(); // Prevent program from terminating
}
The program should be hidden and call the method runProgram every 10 seconds.
When I compile this as a Console Application it works fine. But when I try to compile as a Windows Application it doesn't work. My guess is the timer is not working when compiled as a Windows Application.
How to accomplish this?
You can't call Console.ReadLine(); without a console.
Instead, you should call either Application.Run() (to run a message loop) or Thread.Sleep(Timeout.Infinite) (to hang forever).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With