Hi all,
I am currently working on a PDF app (not using the built in PDF API) and I am having some problems opening documents in a way that will play nice when other apps have the file open as well. I'm not sure if I'm doing something wrong, because I'm seeing the
same issue with other apps, for example the Reader app that ships with Windows 8.1:
- I Open a PDF using Reader with many pages (so they're not all loaded at start-up).
- Switch to desktop and open the same PDF in a desktop app (e.g. Adobe Reader).
- Switch back to reader and start scrolling. You will notice that subsequently loaded pages are now blank.
Why are two apps, both with read-only access, conflicting? If they were both on the desktop or both Store Apps, there would be no conflict.
It seems to me that the correct way to handle files is to open it in Read-only mode. Then when the user wants to save some changes, you try to acquire a ReadWrite stream. If it succeeds, you save and then re-open with Read-only mode. If it fails, you notify
the user (and perhaps ask if they want to save to another file).
If I open the stream in Read-only Mode (file is just a StorageFile from the local file system):
var stream = await file.OpenAsync(FileAccessMode.Read);
Then I get the same problem as Reader had. I get exceptions when I try to read from the file. Once, I even got a message saying an oplock (opportunistic lock) was broken.
If I open the file in ReadWrite mode:
var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
Other store apps can't open the same file.
So it seems to me that I can't make my app play nice with both desktop and store apps at the same time.
***
I am wondering if there is any recommended way to handle file opening which may avoid this type of behaviour. Right now I'm leaning towards making it play nice with other store apps. But perhaps there's a way that can play nice with both that I am not aware
of?
Thanks,
Tomas Hofmann