Does anyone know why sometimes a Directory.Move()
operation in C# hangs/waits instead of throwing an exception immediately?
For example:
If I use the Directory.Move()
method inside a try
block, then navigate to that folder in File Explorer, Windows creates some handles locking it.
Then, I expect the catch block to be executed immediately, but instead it's like the application just hangs for 10-15 seconds before it throws an exception.
The funny thing is, that if I go outside of the folder in File Explorer during these 10-15 seconds, then the application actually completes the Move()
operation.
It's like: instead of throwing an exception immediately, Windows hangs for 10-15 seconds to see if the people who are responsible for the handles (locks) closes these handles by themselves.
Is there a way to make the application throw the exception immediately?