Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created December 14, 2017 06:14
Show Gist options
  • Select an option

  • Save lbargaoanu/48ed0651f1fbbbf9bd7838a299dc4f5a to your computer and use it in GitHub Desktop.

Select an option

Save lbargaoanu/48ed0651f1fbbbf9bd7838a299dc4f5a to your computer and use it in GitHub Desktop.
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