Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to continuously run a c# console application in background

Tags:

c#

I would like to know how to run a c# program in background every five minute increments. The code below is not what I would like to run as a background process but would like to find out the best possible method to do this using this code so that I can implement it on another code. so this process should run after a five minute increment. I know I could use threads to do so, but dont really now how to implement this. I know this is the best way How to run a console application on system Startup , without appearing it on display(background process)? this to run in the background, but how would I have the code running in five minute increments

 class Program
    {
        static void Main(string[] args)
        {
            Console.Write("hellow world");
            Console.ReadLine();
        }
    }
like image 943
user2543131 Avatar asked Dec 01 '22 20:12

user2543131


1 Answers

This app should run continuously, putting out a message every 5 minutes.
Isn't that what you want?

class Program
{
    static void Main(string[] args)
    {
        while (true) {
            Console.Write("hellow world");
            System.Threading.Thread.Sleep(1000 * 60 * 5); // Sleep for 5 minutes
        }

    }
}
like image 175
abelenky Avatar answered Dec 09 '22 13:12

abelenky