如何知道哪些进程正在使用ASP.NET下的文件? [英] How to know which processes is using a file under ASP.NET?

查看:166
本文介绍了如何知道哪些进程正在使用ASP.NET下的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个多线程的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 :

该进程无法访问该文件   因为它是正由另一个   过程

The process cannot access the file because it is being used by another process

我在寻找一种方式来知道到底是哪个进程锁定的文件,所以我可以阻止其访问该文件。或如果是复杂的,我想一个办法来锁定我的线程文件,以便其他线程/进程无法访问它。谢谢你。

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下的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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