My program writes temporary PDF files (using Path.GetTempFileName
) which are then passed to the default PDF handler (typically Adobe Reader) for display. I have a finally
block in my Main method to delete the temp files, but if Adobe Reader is still open when my program closes, the files remain open and can't be deleted.
One solution would just be to leave them there and assume the user will clear out his temporary folder someday; the files are only 1.5 MB each. But is there a better way?
I thought I once read about a way to register files to be deleted on the next reboot, similar to what installers and Windows Update do, but I can't find any information on it now. Is there a function like that I can use here?