简体   繁体   English

在Service Fabric中保持控制台应用程序的活动

[英]Keeping a console application alive in Service Fabric

Are there any established patterns for keeping console applications alive when hosted as guest executables in Service Fabric? 在Service Fabric中作为来宾可执行文件托管时,是否存在用于保持控制台应用程序活动的已建立模式

Adding a Thread.Sleep(Timeout.Infinite) after I've subscribed to Service Bus or similar feels like a bit of a hack to me. 在我订阅了Service Bus或类似的东西之后添加Thread.Sleep(Timeout.Infinite)对我来说感觉有点像黑客。 Other approaches I've seen use Console.ReadKey(), but, again, this feels like a hack. 我见过的其他方法使用Console.ReadKey(),但同样,这感觉就像一个黑客。

Thread.Sleep(Timeout.Infinite) appears to be what's recommended by Microsoft according to their Azure Service Fabric samples in GitHub: Thread.Sleep(Timeout.Infinite)似乎是Microsoft根据他们在GitHub中的Azure Service Fabric示例推荐的内容:

https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/src/GettingStartedApplication/ActorBackendService/Program.cs https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/blob/master/src/GettingStartedApplication/ActorBackendService/Program.cs

Console.ReadKey() is perfectly fine. Console.ReadKey()非常好。 You can Write a message before like 你可以在之前写一条消息

Console.WriteLine("Press any key to end...");
Console.ReadKey();

so the user knows how to end the application. 所以用户知道如何结束应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM