Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Detect Window Close #358

Open
MichaelMay81 opened this issue Jul 23, 2024 · 2 comments
Open

Question: Detect Window Close #358

MichaelMay81 opened this issue Jul 23, 2024 · 2 comments

Comments

@MichaelMay81
Copy link

A part of my app should update continuously.

let delayedDownload (delayInMin:int) = async {
    do! delayInMin * 60 |> Task.Delay |> Async.AwaitTask
    return! remote.getDownloadLinks ()
}

I put this in a Cmd and when I get the 'msg I schedule it again.
But on closing the page this continuous to run.

I need a way to detect, that the window has been closed, to stop that scheduling.

Adding a component and dispatching a 'msg on Dispose seems to work. Although it takes 3 minutes from closing the window until the Dispose and I haven´t figured out how to give the component the dispatch function.

Is there a recommended way to do this?

@MichaelMay81
Copy link
Author

Different approach:

let timer onTick =
        let start dispatch =
            let timer = new Timer(10000.)
            timer.add_Elapsed(fun _ e ->
                printfn $"Timer {e.SignalTime}"
                dispatch onTick)
            timer.Start()
            
            { new System.IDisposable with
                member _.Dispose() =
                    printfn $"Timer disposed"
                    timer.Stop ()
                    timer.Dispose () }
        start

    let subscribe model =
        [ ["timer"], timer Done ]

...
|> Program.withSubscription subscribe
...

Finally the dispatch works (couldn't get that running with a Component), but it still doesn't stop (gets disposed) when the Window closes.

@MichaelMay81
Copy link
Author

I couldn't get it to run. But I found a better way for my specific problem (Update Links when link is actually clicked).
I would still be interested if anyone knows a solution to this, though....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant