Nelson T Joseph
Nelson T Joseph

Reputation: 2763

Close an opened file in Universal App

In my app I opened a file.

private async void OpenFile()
{
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("myVideo.mp4");

    if (file != null)
    {
        var result = await Launcher.LaunchFileAsync(file);
    }
}

I need to close the file after a certain time. How can I close this file?

Upvotes: 2

Views: 1027

Answers (2)

James Croft
James Croft

Reputation: 1680

As @pikciu has mentioned but in a direct response to your question, you won't be able to force the file to close once you've launched it using the Launcher.LaunchFileAsync method as it will be handled by the other application it launches into. Basically, you're getting a fire-and-forget functionality with that method.

Upvotes: 3

Tomasz Pikć
Tomasz Pikć

Reputation: 763

GetFileAsync doesn't open file. You only get handle to a file but it is still closed. If you want to open file you can use for example file.OpenAsync(). It opens file and returns stream. You should dispose stream after operations. LaunchFileAsync opens file but it is handled inside and you don't need to worry about that.

Upvotes: 3

Related Questions