vernou
vernou

Reputation: 7610

Blazor/Electron : Handling close event

I have begin experimental application with Blazor/Electron.

I have forked the project : https://github.com/SteveSandersonMS/BlazorElectronExperiment.Sample

When the application is closed, It need save the application's state. For this, I think it need handle the close event and save application's state before the final close.

How do handle the close event? Have you other solution?

Upvotes: 5

Views: 4178

Answers (1)

dani herrera
dani herrera

Reputation: 51705

Blazor live cycle don't have any method ready to be called OnExit.

An idea may be to implement IDisposable on your component and call saveState from 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();
    }
}

Disclaimer: This approach is an anti-pattern and it is just a workaround until a more elegant solution be ready.

Upvotes: 5

Related Questions