How can I know when Kestrel has started listening?

后端 未结 4 1157
旧时难觅i
旧时难觅i 2021-02-15 13:10

I need to notify systemd that my service has started up successfully, and a task it needs to run after startup requires that the server is already listening

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 14:12

    You may use Microsoft.AspNetCore.Hosting.IApplicationLifetime:

    /// 
    /// Triggered when the application host has fully started and is about to wait
    /// for a graceful shutdown.
    /// 
    CancellationToken ApplicationStarted { get; }
    

    Look into this SO post for the configuration example.

提交回复
热议问题