Problem with file accessing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sushma

    Problem with file accessing

    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.Sta rtupPath + "\\DataAccess\\ FunctionAccessL ist.xml";
    dom.Load(strFil eName);

    Right now i managed like below


    XmlDocument dom = new XmlDocument();
    string strFileName = Application.Sta rtupPath + "\\DataAccess\\ FunctionAccessL ist.xml";
    try
    {
    //FileStream fs = System.IO.File. Open(strFileNam e, FileMode.OpenOr Create, FileAccess.Read , FileShare.None) ;
    // fs.Close();

    dom.Load(strFil eName);
    }
    catch
    {
    try
    {
    Thread.Sleep(10 000);
    dom.Load(strFil eName);
    }
    catch
    {
    InformationAler t.Show("Please wait for some time and launch Programs and Reports, as the Programs list is being refreshed.",tru e );
    Application.Exi t();
    }
    }

    Please post me some work around for this



    EggHeadCafe.com - .NET Developer Portal of Choice

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Problem with file accessing

    Why not just make it so you can share the file for read access
    (FileShare.Read )? That way, you aren't blocking out other processes that
    want to read the file (I'm assuming you are reading the same file in the
    other process in the same way).

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    <sushmawrote in message news:2007428634 13sushmar@proar chitsolutions.c om...
    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.Sta rtupPath +
    "\\DataAccess\\ FunctionAccessL ist.xml";
    dom.Load(strFil eName);
    >
    Right now i managed like below
    >
    >
    XmlDocument dom = new XmlDocument();
    string strFileName = Application.Sta rtupPath +
    "\\DataAccess\\ FunctionAccessL ist.xml";
    try
    {
    //FileStream fs = System.IO.File. Open(strFileNam e,
    FileMode.OpenOr Create, FileAccess.Read , FileShare.None) ;
    // fs.Close();
    >
    dom.Load(strFil eName);
    }
    catch
    {
    try
    {
    Thread.Sleep(10 000);
    dom.Load(strFil eName);
    }
    catch
    {
    InformationAler t.Show("Please wait for some
    time and launch Programs and Reports, as the Programs list is being
    refreshed.",tru e );
    Application.Exi t();
    }
    }
    >
    Please post me some work around for this
    >
    >
    >
    EggHeadCafe.com - .NET Developer Portal of Choice
    http://www.eggheadcafe.com

    Comment

    • sushma

      #3
      Re: Problem with file accessing

      Hi Nicholas

      Thanks for replying..
      That file is being written in the other process. I am not reading the file.

      what should i do now?
      Why not just make it so you can share the file for read access
      (FileShare.Read )? That way, you aren't blocking out other processes that
      want to read the file (I'm assuming you are reading the same file in the
      other process in the same way).

      Hope this helps.

      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      <sushmawrote in message news:2007428634 13sushmar@proar chitsolutions.c om...
      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.Sta rtupPath +
      "\\DataAccess\\ FunctionAccessL ist.xml";
      dom.Load(strFil eName);
      >
      Right now i managed like below
      >
      >
      XmlDocument dom = new XmlDocument();
      string strFileName = Application.Sta rtupPath +
      "\\DataAccess\\ FunctionAccessL ist.xml";
      try
      {
      //FileStream fs = System.IO.File. Open(strFileNam e,
      FileMode.OpenOr Create, FileAccess.Read , FileShare.None) ;
      // fs.Close();
      >
      dom.Load(strFil eName);
      }
      catch
      {
      try
      {
      Thread.Sleep(10 000);
      dom.Load(strFil eName);
      }
      catch
      {
      InformationAler t.Show("Please wait for some
      time and launch Programs and Reports, as the Programs list is being
      refreshed.",tru e );
      Application.Exi t();
      }
      }
      >
      Please post me some work around for this
      >
      >
      >
      EggHeadCafe.com - .NET Developer Portal of Choice
      http://www.eggheadcafe.com



      ___
      Newsgroups brought to you courtesy of www.dotnetjohn.com

      Comment

      Working...