|
| Detecting processes that are being used by the system in VS.net2005 |
 |
Tue, 1 Apr 2008 00:49:25 +0000 |
Hi,
I have developed a “copy_Project” application. Which basically copies any
named directory and all the files and directories inside the main directory
recursively from source to destination location. For example: say one has
developed asp.net application named “Hello World” residing in “C:\program
files” . Then with the help of this “copy project” application. One can
copy this “Hello World” application from the original source path
(C:\program files) to any destination location say “D:\srinivas”. This
“copy project” application is developed on “Windows Vista Ultimate” and
Visual studio 2005 as a windows application.
Currently this application is installed on several vista ultimate systems. But,
on some systems when I tried to copy say “hello world” project directory
from source to destination through “copy_project”, when
“hello_world.sln” is kept opened at the source, the application crashes with
the following error message The process cannot access the file “C:\program
files\hello_world.ncb” because it is being used by another process.
But it works fine on some other systems, its like on 6 vista systems I tested,
it fails on 2 and on other 4 systems its perfectly copying all of the project
files. So, any Idea of why this is happening on some but not on all machines and
what needs to be done to get away with this?.
Secondly, How can I programmatically find out that the project files ( example
hello world.sln or any file) I am trying to copy is opened at the source. And
once I find out, I can simply popup a message saying “you are trying to copy a
file which is opened at the source. So, please close it and try again”.
Any inputs or references will be great.
Thanks,
SC
|
| Post Reply
|
| Re: Detecting processes that are being used by the system in VS.net2005 |
 |
Thu, 3 Apr 2008 08:48:48 +0000 |
Hi,
If the file resource is not released by another process, it will throw this
exception. But you can decline sharing of the current file using FileShare
Enumeration when using the file.
I suggest you release the file resource with Using statement or call Dispose
method, if it can be disposabled.
To detect if the file has been opened, you also can open the file with
FileShare.None, and then if you want to open it again, the operation is failed.
So you can use Try/Catch block to catch this System.IO.IOException, and then
display the warning message.
I hope this helps.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|