Beispiel #1
0
 /// <summary>
 /// Saves now if need.
 /// Don't need to call explicitly. Autosaving is every 2 s, also on process exit and <b>Dispose</b>.
 /// </summary>
 public void SaveIfNeed()
 {
     //AOutput.QM2.Write(_save);
     if (Interlocked.Exchange(ref _save, 0) != 0)
     {
         try {
             var opt = new JsonSerializerOptions {
                 IgnoreNullValues = true, IgnoreReadOnlyProperties = true, WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
             };
             var b = JsonSerializer.SerializeToUtf8Bytes(this, GetType(), opt);
             AFile.SaveBytes(_file, b);
             //AOutput.QM2.Write(GetType().Name + " saved");
         }
         catch (Exception ex) {
             SaveLater();
             AOutput.Write($"Failed to save settings to '{_file}'. {ex.ToStringWithoutStack()}");
         }
     }
 }