Sign in to follow this  
prpradip

Detect if file already opened in first instance of same application

Recommended Posts

Helo everybody THis is C# problem. Scenerio: any file say test.txt is opened in my C# application fileopener.exe Now when i open another instance of fileopener and try to load test.txt. It should detect that test.txt is already opened. How can i do this. Please dont post the method of File.Open(.....) because this method was already tried. I want to know by using Process. i.e System.Diagonastics.Process or Mutex or combined

Share this post


Link to post
Share on other sites
What about creating a temporary lock file in the same directory that has its attribute set to 'hidden' and its existence would mean that the file is currently open. When the file gets closed, that lock file gets deleted. Got the idea from process locks.

Share this post


Link to post
Share on other sites
Quote:
Original post by tariqwalji
What about creating a temporary lock file in the same directory that has its attribute set to 'hidden' and its existence would mean that the file is currently open. When the file gets closed, that lock file gets deleted. Got the idea from process locks.


Thanx I will try...it but other suggestions are also waited

Share this post


Link to post
Share on other sites
Maybe implement a static list of open files in your fileopener class and use mutex lock on it. I am not very familiar with multithreading and if it would work properly.

*EDIT*
Sorry i just saw, that you are talking about executables rather than classes, so forget the above mentioned.

h.

Share this post


Link to post
Share on other sites
You'd have to use shared memory, or named mutexes to do this sort of thing. You can't query the OS to find out if another specific process has opened a specific file (Not without a lot of hacking around, anyway), so you need to record this information yourself. The usual way of checking if another instance of your application is open is with a named mutex, but if you want to share other information (Such as a list of files), you'll need global shared memory (Or you can use WM_COPYDATA, or the C# equivalent).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this