File IO speed problem

C

Cyrus

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
 
J

Jon Skeet [C# MVP]

Cyrus said:
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?
 
H

Herfried K. Wagner [MVP]

* "Cyrus said:
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>
 
C

Cyrus

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();
 
C

Cyrus

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

Cyrus

sorry i solved...

Cyrus said:
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();
 
E

Eric Newton

....and the solution WAS?


--
Eric Newton
C#/ASP Application Developer
(e-mail address removed)-software.com [remove the first "CC."]

cyrus said:
just silly mistake :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top