Change IsReady logic to also wait for connection to be open. This is to prevent actions occurring before the app can act upon them.

This commit is contained in:
Daniel Gidman
2022-02-23 14:57:05 -06:00
parent 79a6ef322c
commit ab694e22fc
2 changed files with 10 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Quobject.SocketIoClientDotNet.Client;
namespace ElectronNET.API
{
@@ -12,10 +13,14 @@ namespace ElectronNET.API
{
public LifetimeServiceHost(IHostApplicationLifetime lifetime)
{
lifetime.ApplicationStarted.Register(() =>
lifetime.ApplicationStarted.Register(async () =>
{
App.Instance.IsReady = true;
// 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.");
});
}