Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 793
vernou Avatar asked Nov 26 '18 12:11

vernou


1 Answers

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.

like image 88
dani herrera Avatar answered Sep 29 '22 07:09

dani herrera