Blazor/Electron : 处理关闭事件

Blazor/Electron : Handling close event

我已经开始使用 Blazor/Electron 进行实验性应用。

我已经分叉了这个项目: https://github.com/SteveSandersonMS/BlazorElectronExperiment.Sample

当应用程序关闭时,需要保存应用程序的状态。 为此,我认为它需要处理关闭事件并在最终关闭之前保存应用程序的状态。

如何处理关闭事件? 你有其他解决方案吗?

Blazor live cycle 没有任何方法可以调用 OnExit

一个想法可能是 implement IDisposable on your component 并调用 saveState 来自 Dispose.

If a component implements IDisposable, the Dispose method is called when the component is removed from the UI.

@using System
@implements IDisposable

...

@functions {
    public void Dispose()
    {
        //anti-pattern work around
        //liveCycle OnUnload don't exists
        save_your_state();
    }
}

免责声明:这种方法是一种反模式,在更优雅的解决方案准备就绪之前,它只是一种变通方法。