By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

File IO methods causing locked process errors

P: n/a
I have a program that takes a single text file, reads thru it, finds a break
point based on information in the file and then outputs a single file, then
continues the process.

The end result is many smaller files from one large file.
I'm using the StreamReader and StreamWriter classes from System.IO to
accomplish this.

On my main form I have some text boxes that allow me to enter a date and the
code uses it to determine which original file to process into smaller ones.
I click a command button and the process starts.

Since my smaller files are all output to the same folder, I delete the files
from the previous run prior to starting a new one.

The problem I'm getting is that I can't seem to get all the files deleted
without catching an exception on a few of them which states that the file is
in use by another process. I can't seem to determine why it thinks these
files are in use. I'm calling .close() on the reader and writer and also
setting them both to =Nothing

The only way I can get it to run correctly is to completely close the
application then re-open it. I'm assuming there's some sort reference to
these files that's only being cleared when the application closes. How can
I call these clearing methods from within the application?

Thanks for any responses. If more information is needed or I need to post
some code let me know.




Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
As well as calling .Close on the Reader/Writer's I would .Dispose of
them also. This should allow all references to clear.

HTH

David

"Chad Dore'" <ch******@NOSPAM.opelousasgeneral.com> wrote in message
news:pk********************@news.easynews.com:
I have a program that takes a single text file, reads thru it, finds a
break
point based on information in the file and then outputs a single file,
then
continues the process.

The end result is many smaller files from one large file.
I'm using the StreamReader and StreamWriter classes from System.IO to
accomplish this.

On my main form I have some text boxes that allow me to enter a date and
the
code uses it to determine which original file to process into smaller
ones.
I click a command button and the process starts.

Since my smaller files are all output to the same folder, I delete the
files
from the previous run prior to starting a new one.

The problem I'm getting is that I can't seem to get all the files
deleted
without catching an exception on a few of them which states that the file
is
in use by another process. I can't seem to determine why it thinks
these
files are in use. I'm calling .close() on the reader and writer and
also
setting them both to =Nothing

The only way I can get it to run correctly is to completely close the
application then re-open it. I'm assuming there's some sort reference
to
these files that's only being cleared when the application closes. How
can
I call these clearing methods from within the application?

Thanks for any responses. If more information is needed or I need to
post
some code let me know.


Nov 20 '05 #2

P: n/a
Yeah I was going to try that but it said dispose() was not accessible in
this context because its "Protected"

I'll do some more reading in the meantime.

<David Williams>; "VB.NET MVP" <da********************@earthlink.net> wrote
in message news:e9**************@TK2MSFTNGP10.phx.gbl...
As well as calling .Close on the Reader/Writer's I would .Dispose of
them also. This should allow all references to clear.

HTH

David

"Chad Dore'" <ch******@NOSPAM.opelousasgeneral.com> wrote in message
news:pk********************@news.easynews.com:
I have a program that takes a single text file, reads thru it, finds a
break
point based on information in the file and then outputs a single file,
then
continues the process.

The end result is many smaller files from one large file.
I'm using the StreamReader and StreamWriter classes from System.IO to
accomplish this.

On my main form I have some text boxes that allow me to enter a date and
the
code uses it to determine which original file to process into smaller
ones.
I click a command button and the process starts.

Since my smaller files are all output to the same folder, I delete the
files
from the previous run prior to starting a new one.

The problem I'm getting is that I can't seem to get all the files
deleted
without catching an exception on a few of them which states that the file is
in use by another process. I can't seem to determine why it thinks
these
files are in use. I'm calling .close() on the reader and writer and
also
setting them both to =Nothing

The only way I can get it to run correctly is to completely close the
application then re-open it. I'm assuming there's some sort reference
to
these files that's only being cleared when the application closes. How
can
I call these clearing methods from within the application?

Thanks for any responses. If more information is needed or I need to
post
some code let me know.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.