问题描述
我正在开发一个多线程的ASP.NET 3.5应用程序,使用了一些文件工作过程中,我发现了以下异常:
I'm developing a multi-threaded ASP.NET 3.5 application, during working with some file, I'm getting the following exception :
该进程无法访问该文件 因为它是正由另一个 过程
我在寻找一种方式来知道到底是哪个进程锁定的文件,所以我可以阻止其访问该文件。或如果是复杂的,我想一个办法来锁定我的线程文件,以便其他线程/进程无法访问它。谢谢你。
I'm looking for a way to know exactly which process is locking that file so I can stop its access to the file. OR if that is complicated, I want a way to lock the file by my thread so other threads/processes can't access it. Thanks.
推荐答案
要真正锁定对资源的访问(你建议的第二个选项),你可以使用一个互斥锁(互斥)。
To actually lock access to the resource (the 2nd option you suggest), you could use a Mutex (a Mutual Exclusion).
我没有做任何这在.NET中,但似乎的的就可以了。
I've not done any of this in .NET, but there seems to be good articles on it.
这篇关于如何知道哪些进程正在使用ASP.NET下的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!