"is createdirectory() in c# thread-safe?" Code Answer


the directory.createdirectory call itself is safe to make from multiple threads. it will not corrupt program or file system state if you do so.

however it's not possible to call directory.createdirectory in such a way to guarantee it won't throw an exception. the file system is an unpredictable beast which can be changed by other programs outside your control at any given time. it's very possible for example to see the following occur

  • program 1 thread 1: call createdirectory for c:tempfoo and it succeeds
  • program 2 thread 1: removes access to c:temp from program 1 user
  • program 1 thread 2: call createdirectory and throws due to insufficient access

in short you must assume that directory.createdirectory, or really any function which touches the file system, can and will throw and handle accordingly.

By AnyDev on March 31 2022

Answers related to “is createdirectory() in c# thread-safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.