Problem with file accessing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi all. My Problem is i have an application that launches an external process on a button click. The other process has a feature of accessing a file during its load and also in its formclosing method.

Now the problem is once i launch and close the application and immediately relaunch the application it gives me an exception saying that the file is in use.

What is the workaround for this since same file is being accessed during the closing of the previous instance and launching of the new instance.

My Code snippet where i get an exception is

XmlDocument dom = new XmlDocument();
string strFileName = Application.StartupPath + "\\DataAccess\\FunctionAccessList.xml";
dom.Load(strFileName);

Right now i managed like below


XmlDocument dom = new XmlDocument();
string strFileName = Application.StartupPath + "\\DataAccess\\FunctionAccessList.xml";
try
{
//FileStream fs = System.IO.File.Open(strFileName, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None);
// fs.Close();

dom.Load(strFileName);
}
catch
{
try
{
Thread.Sleep(10000);
dom.Load(strFileName);
}
catch
{
InformationAlert.Show("Please wait for some time and launch Programs and Reports, as the Programs list is being refreshed.",true );
Application.Exit();
}
}

Please post me some work around for this



EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
.



Relevant Pages

  • Re: Problem with file accessing
    ... Now the problem is once i launch and close the application and immediately ... XmlDocument dom = new XmlDocument; ... string strFileName = Application.StartupPath + ... time and launch Programs and Reports, as the Programs list is being ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reading HKey Current User from Service
    ... for which i need to look into User's registry. ... I cant do a logon user as i dont know user name or ... registry hive without the need to launch an external process (or you can ... useCreateProcessAsUser to launch an external app if you want). ...
    (microsoft.public.win32.programmer.kernel)
  • Re: display tail of monster file
    ... Not absolute that which is better. ... But `tail` will launch an external process that is generally slower. ...
    (perl.beginners)
  • Re: display tail of monster file
    ... Not absolute that which is better. ... But `tail` will launch an external process that is generally slower. ...
    (perl.beginners)
  • Logging exceptions from an external process
    ... I need to be able to launch (or attach) to another process on my machine from ... external process and provide stack trace information. ...
    (microsoft.public.dotnet.general)