예제 #1
0
        public static void Save()
        {
            //dont start saving if already saving
            if (saveTask == null || saveTask.IsCompleted)
            {
                repeatSaveTask = false;
                saveTask       = Task.Run(() =>
                {
                    if (Instance == null)
                    {
                        Instance = new RestoreState();
                    }

                    Instance.WriteFile();
                }).ContinueWith((_) =>
                {
                    if (repeatSaveTask)
                    {
                        RestoreState.Save();
                    }
                });
            }
            else
            {
                //if something updated, schedule another save
                repeatSaveTask = true;
            }
        }
예제 #2
0
 public static void Load()
 {
     if (Instance == null)
     {
         Instance = new RestoreState();
     }
     try
     {
         if (File.Exists(Path))
         {
             var text = File.ReadAllText(Path);
             Instance = JsonSerializer.Deserialize <RestoreState>(text);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }