We have a chatting system where we used to store temporary data in xml file. Due to concurrent access of the xml file we faced a problem that says "this process cannot access the file because it is being used by another process". By implementing threading
logic we overcome this problem. But we have a issue of getting blank xml file whenever server is restarted. For this we are checking if the xml file is corrupt and trying to regenerate well formed xml. As the xml file is corrupt, we can't load it to XmlDataDocument
object. Whenever we are using other alternative we are getting previous problem- "this process cannot access the file because it is being used by another process". Please help to overcome this problem.
What I would do is have a blank copy of the properly formatted XML file in a separate directory. Then when the app start event happens, you can delete the corrupted XML file and then copy the pristine xml file to the new location. Have this code logic inside
your global.asax file and when the app_start fires, this code will run.
kole
Member
2 Points
2 Posts
Xml file getting blank
Feb 22, 2012 05:36 PM|LINK
We have a chatting system where we used to store temporary data in xml file. Due to concurrent access of the xml file we faced a problem that says "this process cannot access the file because it is being used by another process". By implementing threading logic we overcome this problem. But we have a issue of getting blank xml file whenever server is restarted. For this we are checking if the xml file is corrupt and trying to regenerate well formed xml. As the xml file is corrupt, we can't load it to XmlDataDocument object. Whenever we are using other alternative we are getting previous problem- "this process cannot access the file because it is being used by another process". Please help to overcome this problem.
mameenkhn
Contributor
2026 Points
391 Posts
Re: Xml file getting blank
Feb 22, 2012 05:54 PM|LINK
Every time create a new copy of xml file and use that file , when you finished delete the copy file.
Are you disposing the objects...
us GC.Collect when you are done
--------------------------------------------------
Muhammad Amin
محمد امين
bbcompent1
All-Star
33062 Points
8516 Posts
Moderator
Re: Xml file getting blank
Feb 22, 2012 05:55 PM|LINK
What I would do is have a blank copy of the properly formatted XML file in a separate directory. Then when the app start event happens, you can delete the corrupted XML file and then copy the pristine xml file to the new location. Have this code logic inside your global.asax file and when the app_start fires, this code will run.
kole
Member
2 Points
2 Posts
Re: Xml file getting blank
Mar 11, 2012 08:40 AM|LINK
Yes, it works. Thanks a lot for your help.