BinaryReader throws NullReferenceException when being disposed
I have a class MyClass that needs data from a file that will be used
throughout the run of the program. To read in the data I have another
class OpenFileService that derives from IDisposable and uses a
BinaryReader to read in all the data:
internal class OpenFileService : IDisposable
{
#region disposing data
bool disposed = false;
public void Dispose()
{
if (!disposed)
{
Dispose(true);
GC.SuppressFinalize(this);
disposed = true;
}
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
br.Dispose();
}
}
~OpenFileService()
{
Dispose(false);
}
No comments:
Post a Comment