skip to Main Content

I have a console application written in C# that I plan to deploy to Azure. I need to be able to programmatically control its execution — specifically, start and stop the app using code (c#).
Any suggestion?

Since I am new to deploying console applications in Azure, I don’t have any prior knowledge or experience.

2

Answers


  1. You can use Process.start to call a program. See below to Kill a process.
    
    System.Diagnostics.Process.Start().
    Process.Start("notepad.exe", fileName);
    
    foreach (var process in Process.GetProcessesByName("whatever"))
    {
        process.Kill();
    }
    
    Login or Signup to reply.
  2. Does your application support CTRL+C to stop it? That’s how Azure will call your app to stop it.
    If you use a background task, or otherwise cancellable tasks, then it should exit cleanly.

    For example:

    static async Task Main()
    {
        await Host.CreateDefaultBuilder().RunConsoleAsync();
    }
    

    Will automatically support CTRL+C to exit.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search