How-To: Auto-Restart Console App. in .NET

any ideas on how to automatically restart (restart) a console application in .NET?

I know that a forms application has something like this:

Application.Restart();

      

but this is not possible for the console.

Also, NOTE: The problem is that I cannot run two instances of the same application :)

+2


source to share


6 answers


You can create a new process for your application (see the Process class), initiate it, and immediately close your current application.



0


source


Okay, you can run a program that just starts a new instance of your program after exiting the old instance.



0


source


You can create a launcher application that will wait a few seconds and then launch a real console application. Then, when you need an application to restart, you launch the launcher and exit.

There may be other prettier methods, but you will need to explain this part of your question in more detail: "I cannot run two instances of the same application."

0


source


you can put a loop in the Main method when the restart condition is true:

static void Main(string[] args)
{
    do
    {
        Main2(args);
        //Some cleaning may be...
    }while(someCondition)
}

private static void Main2(string[] args)
{
    ....
}

      

0


source


You can try creating a batch file to start the console application and then a service to start the batch file if it is not currently running.

0


source


I may be wrong, but a .NET console application that is an instance of one instance looks like a design error. It looks more like a Windows service to me. Are you sure the console application is correct and that you cannot resolve multiple instances?

0


source







All Articles