barak ben horin
barak ben horin

Reputation: 534

the process cannot access the file because it is being used by another process though streamreader is closed

I'm trying to move a file :

File.Move(fileFullPath, historyFileFullPath);

After i have closed the stream reader :

parser.Close();


/// <summary>
/// closes the file stream
/// </summary>
public void Close()
{
   streamReader.Close();
}

Yet i'm getting the error : the process cannot access the file because it is being used by another process can anybody shed some light ?

Upvotes: 1

Views: 987

Answers (1)

BartoszKP
BartoszKP

Reputation: 35891

You can read about the using statement here. The most basic example for StreamReader is:

using (var sr = new StreamReader(fileName))
{
    //use sr here without worrying 
}

Upvotes: 2

Related Questions