Guest User

Untitled

a guest
Dec 16th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. void Main()
  2. {
  3. DirectoryLocker.Create(@"C:\X");
  4. DirectoryLocker.Create(@"C:\X");
  5. }
  6.  
  7. public static class DirectoryLocker
  8. {
  9. private static ConcurrentDictionary<string, FileStream> _lockFiles = new ConcurrentDictionary<string, FileStream>();
  10.  
  11. public static DirectoryInfo Create(string path)
  12. {
  13. var directory = Directory.CreateDirectory(path);
  14. _lockFiles.GetOrAdd(path, folder => File.Create(Path.Combine(folder, "lock")));
  15. return directory;
  16. }
  17.  
  18. public static void Create(params string[] paths)
  19. {
  20. foreach(var path in paths)
  21. {
  22. Create(path);
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment