9

I created a virtual drive in C# using the Dokan(.NET) library, and it's working quite well.

However, when I try to read a file from the drive in another application I get an exception whenever using operations that read synchronously, like System.IO.File.ReadAllText(...).

The text of the exception is: "Handle does not support synchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened asynchronously".

So if I am interpreting this correctly, .NET apparently tries to read the entire content of the file in a single synchronous operation, but Dokan does not seem to allow that.

But when using a method like ReadAllText I don't really have any control over the way the FileStream is constructed (isn't that the whole point of that method, after all, simply get the file content without having to bother with Streams and Readers and Buffers and whatnot?).

Can I get Dokan to support synchronous I/O access on it's file handles somehow? Or do I have to somehow live with the fact that synchronous operations are just not possible on Dokan-hosted files (and hope that no application that might ever have to work on my virtual drive depends on them)?

Andreas Baus
  • 2,556
  • 3
  • 16
  • 21

1 Answers1

0

Any reason why you need synchronicity in the file read? You could do an async read to a stream, and handle when it finishes via a callback.

This has a good presentation/tutorial on different ways to do async file i/o:

msdn async file io

negEntropy
  • 319
  • 1
  • 5
  • 2
    The type of access is not up to me. I just wanted to provide a virtual file system that anyone could access. If that access happens though, for example, a .NET application written by someone else, who happens to use the `ReadAllText` method to read a file from the virtual drive, there's not much I can do. The file system should just be able to support any kind of access that arbitrary applications might be using. – Andreas Baus Sep 05 '12 at 15:11