我们可以锁定一个目录? [英] can we lock a directory?

查看:124
本文介绍了我们可以锁定一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VSTS 2008 + C#+。NET 3.5的开发控制台应用程序。对于文件的访问,我们可以访问以独占模式文件,它阻止其他进程/从访问的文件线程 - 这有效果锁定的文件

I am using VSTS 2008 + C# + .Net 3.5 to develop a console application. For file access, we can access file in exclusive mode which blocks other process/thread from access the file -- which has the effect of "lock" the file.

我想知道的目录,有没有内置的API或解决方案,使目录独占访问 - 有效果锁定?例如,如果一个线程锁定的目录,其他线程/进程不能打电话Directory.GetFiles,不能写入文件的目录,不能读取从目录等中的文件。

I am wondering for directory, are there any built-in API or solution to make the directory exclusive access -- has the effect of "locked"? For example, if one thread "locks" the directory, other thread/process can not call Directory.GetFiles, can not write file to the directory, can not read a file from the directory, etc.

在此先感谢, 乔治

推荐答案

如果是你自己的过程,可能会干扰你可以使用一个名为互斥同步。这是很难让其他处理,通常的做法是逃避到一个临时(隐藏)目录,做你的工作和复制/移动结果返回。

If it is your own process that might interfere you can use a named Mutex to synchronize. It is very hard to keep out other processes, the usual approach is to evade to a temp (hidden) dir, do your work and copy/move the results back.

这篇关于我们可以锁定一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆