I have a form application that performs a simulation and constantly reads/writes a binary file. Everything works fine if you let it run through. However, if the form is closed/ the simulation is aborted the file-stream is not closed properly - leaving the file locked. Is there a way to make sure all streams closed? I tried the following - but it has no effect... Thanks a lot in advance, T
public BinaryWriter BinWrite;
public BinaryReader BinRead;
public BinaryWriter EnvBinWrite;
public BinaryReader EnvBinRead;
public void theForm_FormClosing(object sender, FormClosingEventArgs e)
{
//Close all binary file reader/writers -- crashes if it cannot overwrite files
foreach (Building B in AllBldgs)
{
try
{
EnvBinRead.Close();
}
catch
{ continue; }
try
{
EnvBinWrite.Close();
}
catch
{ continue; }
try
{
BinRead.Close();
}
catch
{ continue; }
try
{
BinWrite.Close();
}
catch
{ continue; }
}
}