I have created a web application which is creating and updating the xml file on daily basis. i.e. Creating a xml as currentdate.xml. This have all the records of user’s visited i.e IP, refferer, visited page and some more.
So the same file updating from multiple users at same time. So what are the best practice to check the file existence & updating.
I am getting the “File is in use by another process”
Thanks,
Laxmilal
You should not use file in a multi-threaded applications because the concurrency issues.
An example can be this content of a file:
And this is pretty basic issue.
Instead, you can use file-based database (such as SQLite) or, of course, a proper database (not necessarily RDBMS).
Or in the worst case you have to synchronise the writes manually:
NOTE here:
FileMode.Appendwill take care of that.Another option would be to use Log4net that does handle the concurrency much better.
So that you can write your stats as log files: