Hi peeps
I'm writing a little application whereby I want to write the results of the operations to a file.
Basically what I want to do is open a stream to a file (I'm thinking FileStream, but am open to suggestions), write data to the file, then close it at a later date.
So I've got a class called ReportFile, with methods:
.Create( string path )
.WriteInfo( string a, string b, string c ) ; //Or something like this...
//Then sometime in the future
.Close()
So the class using the ReportFile class will create an instance, call WriteInfo(..)
multiple times until it is finished doing whatever it needs to do, then call Close()
at some point in the future.
Now I know I need to implement a Dispose pattern on the ReportFile class to ensure that if anything goes screwey that the handle to the file gets appropriately dealt with.
However I haven't been able to find anything thus far on the interweb showing a good way of keeping the file open and then checking to see if it needs to be closed, most of the examples just open the file do the writing, then close it - all within a using{}
construct.
In the ReportFile class I want to be able to check if the FileStream instance is not closed so that I can close it and free up resource.
Anyone know of a good link to reference or any other advice ?
(Ohh I should mention that I don't do C# full time, it's only a hobby thing, so if this is a dumb question, my apologies ;-)