Функция иногда не прочитывает файл
Как это исправить?
static public void ReadParam()
{
BinaryReader br;
string path = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName + "\\noticeprogramdata.dat";
try
{
string locale = string.Empty;
int enume = -1;
List<ScheduleCell> cells = new List<ScheduleCell>();
br = new BinaryReader(new FileStream(path, FileMode.OpenOrCreate));
try
{
newStart = br.ReadBoolean();
wD1 = br.ReadBoolean();
wD2 = br.ReadBoolean();
wD3 = br.ReadBoolean();
wD4 = br.ReadBoolean();
eD1 = br.ReadBoolean();
eD2 = br.ReadBoolean();
eD3 = br.ReadBoolean();
eD4 = br.ReadBoolean();
dayToday = br.ReadByte();
DateTimeOffset.TryParse(br.ReadString(), CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTimeOld);
locale = br.ReadString();
enume = br.ReadInt32();
for (;;)
{
cells.Add(new ScheduleCell(br.ReadString(), br.ReadInt32()));
}
}
catch (EndOfStreamException exc)
{
Console.WriteLine(exc.Message.ToString());
}
br.Close();
schedule = new ScheduleCollection(cells, (ScheduleCollection.SortDirectionEnum)enume, locale);
}
catch (Exception exc)
{
Console.WriteLine(">>>"+exc.Message.ToString());
if (br != null)
br.Close();
}
}
использую этот код в проекте windows forms