Jump to content
  • Advertisement
Sign in to follow this  
prpradip

Detect if file already opened in first instance of same application

This topic is 3811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Download Handle from sysinternals, and run "handle processname". :)

(And yes, there are horrible race condition issues with this).

Share this post


Link to post
Share on other sites
Quote:
Please dont post the method of File.Open(.....) because this method was already tried.
What was wrong with it? It works fine for me...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!