Dan
Dan

Reputation: 31

C# .Net file in use issue

I'm having an issue opening files that have recently been closed by the .Net framework. Basically, what happens is the following:

This sequence can intermittently fail either after the WriteXML or the File.Copy with a file in use exception.
I'm guessing it could be the Windows write cache not flushing right away. Can anyone confirm that this could be causing my issue? Any solutions to suggest?

Thanks,
Dan

Upvotes: 2

Views: 483

Answers (3)

Development 4.0
Development 4.0

Reputation: 2763

Could this possibly be caused by an over eager anti virus program? They may place a lock on it while they inspect the file

Upvotes: 1

Joe Pitz
Joe Pitz

Reputation: 2464

Not sure how you are opening the file.

I was having the same problem after closing a text file.

This is what I found that worked:

if (null != sReader) ((IDisposable)sReader).Dispose();

where sreader is

StreamReader sReader

Upvotes: 0

Michael D. Irizarry
Michael D. Irizarry

Reputation: 6302

Note: If your using FileStream remember to close it.

Upvotes: 0

Related Questions