Re: Problem with file accessing

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



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@xxxxxxxxxxxxxxxxxxxxxxxxxxx

<sushma> wrote in message news:200742863413sushmar@xxxxxxxxxxxxxxxxxxxxxxxxx
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
    ... I am not reading the file. ... Now the problem is once i launch and close the application and immediately ... string strFileName = Application.StartupPath + ... time and launch Programs and Reports, as the Programs list is being ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with file accessing
    ... My Problem is i have an application that launches an external process on a button click. ... 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. ... XmlDocument dom = new XmlDocument; ... InformationAlert.Show("Please wait for some time and launch Programs and Reports, as the Programs list is being refreshed.",true); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Substitute/alternate for Quick Launch
    ... > Note that although the Quick Launch Bar is on the taskbar by default, ... You can drag it off the taskbar and put it ... >>> complicated to launch programs now. ... >>> similar to Quick Launch (wish to launch programs with mouse not ...
    (microsoft.public.windowsxp.general)
  • Lock a launched application?
    ... I am wanting to create a launch bed application for some people and one of ... the specifics they have asked for is this. ... They want to be able to only launch programs only from this application ...
    (borland.public.delphi.nativeapi)
  • Re: Substitute/alternate for Quick Launch
    ... You can resize the quick launch bar to suit your needs, ... hold so many icons before filling up the taskbar. ... > Quick Launch (wish to launch programs with mouse not keyboard) and it ...
    (microsoft.public.windowsxp.general)