Perhaps I could make the application domain and connect to the DomainUnload event, but I would like to do this in the main application domain.
In .net there is no analogue: (
You have the right idea, you will need to explicitly delete it.
// Delete the previously created file. File.Delete(filepath);