I want my program to detect when a file is closed in order to encrypt it again.

Is there a better way to do this than checking periodically the process list if the program opened the file is still open?