mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-13 21:24:00 +00:00
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Quobject.SocketIoClientDotNet.Client;
|
|
|
|
namespace ElectronNET.API
|
|
{
|
|
/// <summary>
|
|
/// Base class that reports if ASP.NET Core has fully started.
|
|
/// </summary>
|
|
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.");
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Triggered when the application host is ready to start the service.
|
|
/// </summary>
|
|
/// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Triggered when the application host is performing a graceful shutdown.
|
|
/// </summary>
|
|
/// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
} |