Keeping a console application alive in Service Fabric

469 Views Asked by At

Are there any established patterns for keeping console applications alive when hosted as guest executables in 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. Other approaches I've seen use Console.ReadKey(), but, again, this feels like a hack.

2

There are 2 best solutions below

0
On BEST ANSWER

Thread.Sleep(Timeout.Infinite) appears to be what's recommended by Microsoft according to their Azure Service Fabric samples in GitHub:

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

0
On

Console.ReadKey() is perfectly fine. 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.