Question

I made small program, which you don't have to install. So when I want to showHelp, I have to extract it from Resources, this works great, and I save a path to this file.

Then when I call ShowHelp, I pass path to extracted file. In closing event, I try to delete this file, and here is problem.

When I use

Help.ShowHelp(this,pathToChmFile);

it works great, I can delete file, but when I pass even topicId, like this

Help.ShowHelp(this, pathToChmFile, HelpNavigator.TopicId, "10");

then when FormClosing is called, I can't delete chm file, because it is opened by my process. But why when I show it without topicId, I can delete it?

Because you can't uninstall my program, I want to clean "rubbish" after myself, but now I can't...

Was it helpful?

Solution

Creating litter in this scenario is pretty inevitable. You cannot ensure that the file gets deleted. For one, a user typically uninstalls your program when it crashes too much. You cannot extract the resource into the same directory as your EXE, the typical install locations are not accessible to your program for writing. UAC stops this. The user will get a prompt to elevate when she copies your EXE but no such prompt is provided for your own actions. You must extract to %AppData% or the TEMP folder, your user will never find the file back. At least there's a mechanism to delete old junk from TEMP so favor using Path.GetTempPath().

For another, the lock is inevitable as well, it is held by another process. The Windows hh.exe program displays the .chm file content. There isn't anything reasonable you can do when the user exits your program but didn't close the help viewer first. There's no reliable way to find the correct instance of hh.exe to kill it, there can be multiple.

So you're stuck with the litter, Path.GetTempPath() is least objectionable. Unless you deploy the .chm file in the same directory as the EXE. If not from a .zip file, creating a setup.exe program is quite trivial with a Setup project, don't skip the one thing that solves your problem and makes your user comfortable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top