There are BinaryReader and BinaryWriter, which simultaneously write and read. There is a progressBar. When I close the application while I work, I get Exception in the progressBar and use the delegate to do Close () & Dispose () BinaryReader, BinaryWriter and FileStream, which is used in BinaryReader. Nevertheless, the file for some reason is not released.
streamRead - FileStream; reader - BinaryReader;
using (streamRead = new FileStream(filePath, FileMode.Open)) { reader = new BinaryReader(streamRead); writer - BinaryWriter
using (writer = new BinaryWriter(File.Open(this.txbxArchivePath.Text + @"\" + this.txbxArchiveName.Text + ".Haffman", FileMode.Create, FileAccess.ReadWrite, FileShare.Read))){ } the method that I call with the delegate:
private void DisposeAll() { this.reader.Close(); this.writer.Close(); streamRead.Close(); this.reader.Dispose(); this.writer.Dispose(); streamRead.Dispose(); this.Dispose(); }
File.Openreturns aFileStream. It must be saved in a separate variable (field) and also closed / disposed. - Alexander Petrov