I always find that when there is a write operation immediately after the
read operation, it throws this exception

An unhandled exception of type 'System.IO.IOException' occurred in
mscorlib.dll
Additional information: The process cannot access the file
"D:\Projects\pro.dat" because it is being used by another process.

how to solve this problem

Re: File IO speed problem by Jon

Jon
Mon Nov 10 04:14:49 CST 2003

Cyrus <CyrusChiu@kfsolution.com> wrote:
> I always find that when there is a write operation immediately after the
> read operation, it throws this exception
>
> An unhandled exception of type 'System.IO.IOException' occurred in
> mscorlib.dll
> Additional information: The process cannot access the file
> "D:\Projects\pro.dat" because it is being used by another process.
>
> how to solve this problem

Have you closed the reading stream before you start writing again?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: File IO speed problem by hirf-spam-me-here

hirf-spam-me-here
Mon Nov 10 04:15:48 CST 2003

* "Cyrus" <CyrusChiu@kfsolution.com> scripsit:
> I always find that when there is a write operation immediately after the
> read operation, it throws this exception
>
> An unhandled exception of type 'System.IO.IOException' occurred in
> mscorlib.dll
> Additional information: The process cannot access the file
> "D:\Projects\pro.dat" because it is being used by another process.
>
> how to solve this problem

Post your code.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Re: File IO speed problem by ~cch~

~cch~
Mon Nov 10 08:45:54 CST 2003

i use streamreader and streamwriter
i did close them.

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> ???
news:bonoou$1fismf$1@ID-208219.news.uni-berlin.de ???...
> * "Cyrus" <CyrusChiu@kfsolution.com> scripsit:
> > I always find that when there is a write operation immediately after the
> > read operation, it throws this exception
> >
> > An unhandled exception of type 'System.IO.IOException' occurred in
> > mscorlib.dll
> > Additional information: The process cannot access the file
> > "D:\Projects\pro.dat" because it is being used by another process.
> >
> > how to solve this problem
>
> Post your code.
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>
>
> <http://www.plig.net/nnq/nquote.html>



Re: File IO speed problem by hirf-spam-me-here

hirf-spam-me-here
Mon Nov 10 12:37:16 CST 2003

* "~cch~" <cyruschiu@hkbn.net> scripsit:
> i use streamreader and streamwriter
> i did close them.

Post the code snippet you use to perform the operation.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Re: File IO speed problem by Cyrus

Cyrus
Mon Nov 10 20:23:14 CST 2003

StreamReader sr = new
StreamReader(File.OpenRead(Environment.CurrentDirectory + "\\Inipro.dat"));
// StreamReader sr = new StreamReader(keyFile.OpenRead());

if (sr.ReadLine() != null)
{
prodCode = this.Decode(sr.ReadLine());
actCode = this.Decode(sr.ReadLine());
pass = VerifyActCode();
}
sr.Close();

UnicodeEncoding byteConverter = new UnicodeEncoding();
// StreamWriter sw = new StreamWriter(keyFile.OpenWrite());
StreamWriter sw = new
StreamWriter(File.OpenWrite(Environment.CurrentDirectory + "\\Inipro.dat"));

sw.WriteLine(byteConverter.GetString(this.GetRandomBytes()));
sw.WriteLine(this.Encode(prodCode));
sw.WriteLine(this.Encode(actCode));
sw.Flush();
sw.Close();



"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:boom95$1ghmjg$6@ID-208219.news.uni-berlin.de...
> * "~cch~" <cyruschiu@hkbn.net> scripsit:
> > i use streamreader and streamwriter
> > i did close them.
>
> Post the code snippet you use to perform the operation.
>
> --
> Herfried K. Wagner
> MVP · VB Classic, VB.NET
> <http://www.mvps.org/dotnet>
>
> <http://www.plig.net/nnq/nquote.html>



Re: File IO speed problem by Cyrus

Cyrus
Tue Nov 11 03:28:10 CST 2003

even i close the filestream after closing the streamwriter
the error still happen....

"Cyrus" <CyrusChiu@kfsolution.com> wrote in message
news:euDyhn$pDHA.2404@TK2MSFTNGP12.phx.gbl...
> StreamReader sr = new
> StreamReader(File.OpenRead(Environment.CurrentDirectory +
"\\Inipro.dat"));
> // StreamReader sr = new StreamReader(keyFile.OpenRead());
>
> if (sr.ReadLine() != null)
> {
> prodCode = this.Decode(sr.ReadLine());
> actCode = this.Decode(sr.ReadLine());
> pass = VerifyActCode();
> }
> sr.Close();
>
> UnicodeEncoding byteConverter = new UnicodeEncoding();
> // StreamWriter sw = new StreamWriter(keyFile.OpenWrite());
> StreamWriter sw = new
> StreamWriter(File.OpenWrite(Environment.CurrentDirectory +
"\\Inipro.dat"));
>
> sw.WriteLine(byteConverter.GetString(this.GetRandomBytes()));
> sw.WriteLine(this.Encode(prodCode));
> sw.WriteLine(this.Encode(actCode));
> sw.Flush();
> sw.Close();
>
>
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:boom95$1ghmjg$6@ID-208219.news.uni-berlin.de...
> > * "~cch~" <cyruschiu@hkbn.net> scripsit:
> > > i use streamreader and streamwriter
> > > i did close them.
> >
> > Post the code snippet you use to perform the operation.
> >
> > --
> > Herfried K. Wagner
> > MVP ?VB Classic, VB.NET
> > <http://www.mvps.org/dotnet>
> >
> > <http://www.plig.net/nnq/nquote.html>
>
>



Re: File IO speed problem by Cyrus

Cyrus
Tue Nov 11 03:47:55 CST 2003

sorry i solved...

"Cyrus" <CyrusChiu@kfsolution.com> wrote in message
news:euDyhn$pDHA.2404@TK2MSFTNGP12.phx.gbl...
> StreamReader sr = new
> StreamReader(File.OpenRead(Environment.CurrentDirectory +
"\\Inip