Loading a local video with webview in WPF leaves it locked

229 views Asked by At

I have a WPF application that loads a local web page into a WebView with NavigateToLocal.

The website has a VIDEO tag that plays a local video file and loads everything correctly.

The problem is that it leaves that file completely locked until I close the application, even if I close the window that contains the WebView.

This prevents me from refreshing the page, because the video fails, or delete the file when it is no longer needed.

I tried to load a different local video file or "clean" the player somehow, but nothing works.

1

There are 1 answers

0
Evariste On

The problem is that the WebView control actually uses an external process to run the browser (WWAHost.exe if I'm correct). This process does not terminate automatically when closing your WPF window. Add an event to catch the window closing event, and use this code:

    private void Window_Closed(object sender, EventArgs e)
    {
        myWebView.Process.Terminate();
    }