473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.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
Apr 28 '07 #1
2 1454
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]
- mv*@spam.guard.caspershouse.com

<sushmawrote in message news:20*****************@proarchitsolutions.com...
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

Apr 28 '07 #2
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]
- mv*@spam.guard.caspershouse.com

<sushmawrote in message news:20*****************@proarchitsolutions.com...
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

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
Apr 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: William LaMartin | last post by:
For several weeks I have been trying to track down the cause of disappearing session and application variables. At the site that gives me the problem--a Microsoft FrontPage site--I note that there...
5
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
11
by: E.T. Grey | last post by:
Hi, I have an interesting problem. I have a (LARGE) set of historical data that I want to keep on a central server, as several separate files. I want a client process to be able to request the...
13
yolenman
by: yolenman | last post by:
Hello - This is my first posting to this group, so please bear with me. Also note, that while I'm intelligent, databases are not in my field of knowledge. I'm working with a small limousine...
1
by: leenadiwan | last post by:
Friends, Im having problem with accessing a JS file placed in another folder from a JSP popup. I tried all the following: <SCRIPT LANGUAGE="JavaScript1.1" ...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
0
by: priyamtheone | last post by:
Hi everyone, I'm working with VB.Net 2005(.Net framework 2.0). I am having a problem in accessing the items in a menustrip of a form. Suppose there is an item in a menustrip named FILE. Under the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.