Before writing to the file make sure the file isn't currently in the process of being locked.