How to write a linux daemon with .Net Core

后端 未结 5 2061
离开以前
离开以前 2021-01-31 05:22

I could just write a long-running CLI app and run it, but I\'m assuming it wouldn\'t comply to all the expectations one would have of a standards-compliant linux daemon (respond

5条回答
  •  情书的邮戳
    2021-01-31 05:59

    Have you tried Thread.Sleep (Timeout.Infinite) ?

    using System;
    using System.IO;
    using System.Threading;
    
    namespace Daemon {
        class Program {
            static int Main(string[] args) {
                if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
                    Log.Critical("Windows is not supported!");
                    return 1;
                }
                Agent.Init();
                Agent.Start();
                if (Agent.Settings.DaemonMode || args.FirstOrDefault() == "daemon") {
                    Log.Info("Daemon started.");
                    Thread.Sleep(Timeout.Infinite);
                }
                Agent.Stop();
            }
        }
    }
    

提交回复
热议问题