Integrating dokan-dotnet into existing application without blocking it
See original GitHub issueI have an application, that while running I would like for it to publish a custom file system for internal data.
Since this application is doing other things as well, as well as responding to shutdown commands that terminates the application in an orderly fashion I’m looking for how to integrate Dokan into this.
I cloned the dokan-dotnet repository and tried to change the RegistryFS example to do its own unmounting. If I simply run it, and hit Ctrl-C, I see “send global release for r:”, no error messages, and the drive disappears.
Now I want to “unblock” the main program, so I tried changing it to this:
internal class Program
{
private static void MountDrive()
{
try
{
var rfs = new RFS();
rfs.Mount("r:\\", DokanOptions.DebugMode | DokanOptions.StderrOutput);
}
catch (DokanException ex)
{
Console.WriteLine(@"Error: " + ex.Message);
}
}
private static void Main()
{
Task.Factory.StartNew(MountDrive);
Console.WriteLine("Hit enter to unmount");
Console.ReadLine();
Dokan.Unmount('r');
}
}
Now, when I hit Enter, this is output:
send global release for r:
Ioctl failed for wait with code 995.
Thread will be terminated
Ioctl failed for wait with code 995.
Thread will be terminated
Ioctl failed for wait with code 995.
Thread will be terminated
Ioctl failed for wait with code 995.
Thread will be terminated
Ioctl failed for wait with code 995.
Thread will be terminated
05/31/2021 14:29:50 - [DokanNet] UnmountedProxy:
05/31/2021 14:29:50 - [DokanNet] Context {<null>, False, False, False, False, #0, False, False}
05/31/2021 14:29:50 - [DokanNet] UnmountedProxy Return : Success
send global release for r:
DokanError: Ioctl 0x92010 failed with code 122 on Device \\.\Dokan_1
Failed to unmount: r:
Now, the drive does disappear from Windows Explorer, but all those error messages tells me this isn’t how I am supposed to do it.
So my question is this. How can I, from a separate thread in my program, correctly unmount a Dokan-DotNet mounted file system?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Good, thanks! Man I have many ideas for the use of this library 😃 Thanks!
I would strongly recommend you to design the application so that you wait for all Dokan threads before exiting. In this particular case, since you start a task, assign the returned Task object from StartNew to a variable and call the Wait method of that object before returning from Main method.