Reputation: 2763
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
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
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