As “immediately” as possible. There can easily be some lag due to outstanding writes, delay in updating the directory info etc. It could also be anti-virus software checking your changed file.
This may be a rare case where a Thread.Sleep(1)
is called for. But to be totally safe you will have to catch the (any) exception and try again a set number of times.