Browse Source

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

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

10
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,11 +42,16 @@ namespace Signal_Generator.Properties {
public static ObservableCollection<IAnalogSignal> LoadSignals() public static ObservableCollection<IAnalogSignal> LoadSignals()
{ {
BinaryFormatter formatter = new BinaryFormatter(); BinaryFormatter formatter = new BinaryFormatter();
try
{
using (FileStream fs = new FileStream("settings.dat", FileMode.Open)) using (FileStream fs = new FileStream("settings.dat", FileMode.Open))
{ {
if (!fs.CanRead) return null;
return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs); return (ObservableCollection<IAnalogSignal>)formatter.Deserialize(fs);
} }
} catch
{
return null;
}
} }
} }
} }

Loading…
Cancel
Save