using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Hosting; using Quobject.SocketIoClientDotNet.Client; namespace ElectronNET.API { /// /// Base class that reports if ASP.NET Core has fully started. /// internal class LifetimeServiceHost : IHostedService { public LifetimeServiceHost(IHostApplicationLifetime lifetime) { lifetime.ApplicationStarted.Register(async () => { // wait till the socket is open before setting app to ready while(BridgeConnector.Socket.Io().ReadyState != Manager.ReadyStateEnum.OPEN) { await Task.Delay(50).ConfigureAwait(false); } App.Instance.IsReady = true; Console.WriteLine("ASP.NET Core host has fully started."); }); } /// /// Triggered when the application host is ready to start the service. /// /// Indicates that the start process has been aborted. public Task StartAsync(CancellationToken cancellationToken) { return Task.CompletedTask; } /// /// Triggered when the application host is performing a graceful shutdown. /// /// Indicates that the shutdown process should no longer be graceful. public Task StopAsync(CancellationToken cancellationToken) { return Task.CompletedTask; } } }