Browse Source

Быстрофикс ошибки при которой приложение не запускалось (при отсутствующем или поврежденном файле)

master
Никита 6 years ago
parent
commit
2d98fb99be
  1. 14
      Signal Generator/Settings.cs

14
Signal Generator/Settings.cs

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
@ -41,10 +42,15 @@ namespace Signal_Generator.Properties {
public static ObservableCollection<IAnalogSignal> LoadSignals() public static ObservableCollection<IAnalogSignal> LoadSignals()
{ {
BinaryFormatter formatter = new BinaryFormatter(); BinaryFormatter formatter = new BinaryFormatter();
using (FileStream fs = new FileStream("settings.dat", FileMode.Open)) try
{ {
if (!fs.CanRead) return null; using (FileStream fs = new FileStream("settings.dat", FileMode.Open))
return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs); {
return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs);
}
} catch
{
return null;
} }
} }
} }

Loading…
Cancel
Save