StreamWriter.Close() in Windows Service leaves handles

  • Thread starter Thread starter John Mark Howell
  • Start date Start date
J

John Mark Howell

OK, I've confirmed this: If you use a StreamWriter and don't wrap it in a
using statement, simply calling Close() does not always release the handle.
It does close the file but it appears to leave some type of object
containing a handle out there. I created a simple windows service that
called a method that simply wrote out a string to a file. It ran for a
month, slowly increasing the handles number listed in the Task Manager until
it finally simply hung up without an error. It did not terminate, it simply
did nothing (used no CPU). Wrapping the file I/O code in a using seems to
have eliminated the slowly increasing number of handles.

My environment is:
Windows XP Pro (no service pack)
.Net 1.1 & C#
1M RAM, 120G hd

Has anyone else found this?
 
If you call Close as the first statement in finally block, it should be
the same as "using". Close and Dispose method of the StreamWriter just
do the same thing.
Did you call it in finally block? If not, an exception might prevent
Close method from being called.

Thi
 
Yes, but I have found that it only slowed the number of handles being
created. I'm no longer sure that the StreamWriter class was the culprit.
I'm looking now. Does anyone know what type of handles that is being
referred to when looking at the Windows Task Manager?
 
Back
Top