admin管理员组文章数量:1122846
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.
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.
Share Improve this question edited Nov 21, 2024 at 14:55 DarkBee 15.8k8 gold badges69 silver badges110 bronze badges asked Nov 21, 2024 at 14:48 sarasara 11 bronze badge 3- 2 How are you planning to "deploy" it? What is going to be hosted in? – Fildor Commented Nov 21, 2024 at 14:57
- 1 Do you really want to start/stop the entire app or just control if it is performing a specific action? – DavidG Commented Nov 21, 2024 at 14:59
- Why not export the functionality of the CLI as a DLL instead? – Valerij Dobler Commented Nov 21, 2024 at 15:14
2 Answers
Reset to default -1Does 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.
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();
}
本文标签: cHow to programmatically stop and start a console applicationStack Overflow
版权声明:本文标题:c# - How to programmatically stop and start a console application? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309761a1934135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论