Hello,
Note : I use a translation app. Sorry if it's not always very understandable.
I'm developing a UWP application, and I'm having a problem with managing a file type, the CBZ extension.
Some files open without a problem, others the file never opens and blocks the Task.
Here's the code I use :
Task loadEbookTask = Task.Factory.StartNew(() =>
{
Stream streamEbook = WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(ebookFile).Result;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Content = new ZipArchive(streamEbook, ZipArchiveMode.Read, false);
// Pour charque archive, prendre que des extensions valident.
foreach (var file in Content.Entries)
{
string extension = Path.GetExtension(file.Name).ToLower();
bool isFileExtensionOk = EbooksManager.AvailableExtensionsImage.Contains(extension);
if (isFileExtensionOk)
{
ArchivesExploitable.Add(file);
}
}
TotalPage = Convert.ToUInt32(ArchivesExploitable.Count());
});
if (loadEbookTask.Wait(4000))
{
EbookCbz.LoadEbook = EbookLoad.Ok;
}
else
{
EbookCbz.LoadEbook = EbookLoad.Timeout;
}
It's looping on :
Stream streamEbook = WindowsRuntimeStorageExtensions.OpenStreamForReadAsync(ebookFile).Result;
In Visual Studio, memory doesn't go up any more, but the Garbage Collector keeps being called.
With the Task.Wait(4000), it does not stop the Task, so it does not stop turning in background.
And if I open another file, a new task is created, and will turn into a background task.
My question is:
- Is there a method that open a file, and that it is possible to cancel if it exceeds a certain time.