Created
December 14, 2017 06:14
-
-
Save lbargaoanu/48ed0651f1fbbbf9bd7838a299dc4f5a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void Main() | |
| { | |
| DirectoryLocker.Create(@"C:\X"); | |
| DirectoryLocker.Create(@"C:\X"); | |
| } | |
| public static class DirectoryLocker | |
| { | |
| private static ConcurrentDictionary<string, FileStream> _lockFiles = new ConcurrentDictionary<string, FileStream>(); | |
| public static DirectoryInfo Create(string path) | |
| { | |
| var directory = Directory.CreateDirectory(path); | |
| _lockFiles.GetOrAdd(path, folder => File.Create(Path.Combine(folder, "lock"))); | |
| return directory; | |
| } | |
| public static void Create(params string[] paths) | |
| { | |
| foreach(var path in paths) | |
| { | |
| Create(path); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment