Пример #1
0
#pragma warning disable IDE1006 // Naming Styles

        private static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
        {
            StatusBarViewModel statusBar = null;
            bool runGui = false;

            try
            {
                Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

                runGui = await CommandInterpreter.ExecuteCommandsAsync(args);

                if (!runGui)
                {
                    return;
                }
                Logger.LogStarting("Wasabi GUI");

                BuildAvaloniaApp()
                .BeforeStarting(async builder =>
                {
                    MainWindowViewModel.Instance = new MainWindowViewModel();
                    statusBar = new StatusBarViewModel();
                    MainWindowViewModel.Instance.StatusBar = statusBar;

                    await Global.InitializeNoWalletAsync();

                    statusBar.Initialize(Global.Nodes.ConnectedNodes, Global.Synchronizer, Global.UpdateChecker);

                    if (Global.Network != Network.Main)
                    {
                        MainWindowViewModel.Instance.Title += $" - {Global.Network}";
                    }

                    Dispatcher.UIThread.Post(() =>
                    {
                        GC.Collect();
                    });
                }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance);
            }
            catch (Exception ex)
            {
                Logger.LogCritical <Program>(ex);
                throw;
            }
            finally
            {
                statusBar?.Dispose();
                await Global.DisposeAsync();

                AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
                TaskScheduler.UnobservedTaskException      -= TaskScheduler_UnobservedTaskException;

                if (runGui)
                {
                    Logger.LogInfo($"Wasabi GUI stopped gracefully.", Logger.InstanceGuid.ToString());
                }
            }
        }