Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a requirement wherein i have to read/write a single xml file across 2 application, one of which is a windows form application and others an windows service. Is there any best approach or a design pattern defined to achieve this, which will make sure there is no deadlock when both apps try to access this file. On the windows service side, I thought of making use of event driven mechanism based upon the "last updated time" info of the file.
Posted

It's a bad idea to have multiple programs write to the same file at the same time.

If you are only reading then you can :

1) Read the entire file to memory first then process (if it is small enough) with File.ReadAllText()
2) Open the file in shared read mode : http://msdn.microsoft.com/en-us/library/y973b725%28v=vs.110%29.aspx[^]

To detect file changes use the FileSystemWatcher : FileSystemWatcher - Pure Chaos (Part 1 of 2)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900