I have a Windows Service that I wrote in C#. This "brains" of the app are in a class named Driver
. This class asynchronously starts up a bunch of threads to do a number of things. There's nothing "blocking" in this code. The Driver is responsible for starting these threads, listening for specific events, and stopping the threads on these events.
At this time, I've wrapped this code as a Windows Service. The OnStart
, OnStop
, etc methods are just wrappers into this class. The Windows Service runs as I want it to. However, now, I want to run this code in a Docker container. My question is, how do I modify this code to become a long running process instead of a Windows Service.
My initial thought was to wrap my code in a Console app. Then, I would move the code from OnStart
to the body of the Console app. After that code, I would just have a while(true){}
statement to keep the console app alive. However, this feels like a hack.
Is this approach a hack? Or, is there a "real" way to do this? If so, what is the recommended approach for having a long running C# app in Docker?