How to open a pdf a second time?

How do I have to close a document? Because if I open the same pdf-file twice I get an System.UnauthorizedAccessException. (Doc A --> Doc B works, but Doc A --> Doc A crashes).

The crash happens on StorageFile.GetFileFromPathAsync(path) because the file is still open.

Here is my Code

private async void OpenPage(String path)
        {
            StorageFile file = await StorageFile.GetFileFromPathAsync(path);

            if (file != null)
            {
                IRandomAccessStream stream = await
                    file.OpenAsync(FileAccessMode.ReadWrite);
                if (doc != null) {
                    doc.Dispose();
                }
                doc = new pdftron.PDF.PDFDoc(stream);
                MyPDFViewCtrl.SetDoc(doc);
                
            }
        }

Since PDFDoc has a handle on a system file resource, you cannot rely on the GC to release that for you, since it might be a long time before that happens. Instead you need to force the PDFDoc.Dispose(), by either calling it explicitly, or through a ‘using’ statement.

You should look the PDFViewCtrl sample that comes with the SDK, and look at the Close Doc method (not sure the exact name), it has the code you want.

It is something along these lines.

`
auto oldDoc = MyPDFViewCtrl.GetDoc();
MyPDFViewCtrl.SetDoc(newDoc);
if(oldDoc != null)
{

oldDoc.Dispose();

}

`