public async Task WriteHistory() { await Dispatcher.BeginInvoke((Action)(() => { if (!StaticDeclarations.IsIncognito) { try { if (!LastWebsite.Equals(WebView.Address)) { if (!System.IO.File.Exists(StaticDeclarations.Historypath)) { var history = new HistItem(); history.Title = Title; history.Url = WebView.Address; var histories = new List <HistItem>(); histories.Add(history); var newJson = JsonConvert.SerializeObject(histories); File.WriteAllText(StaticDeclarations.Historypath, newJson); LastWebsite = WebView.Address; } else { HistItem history = new HistItem(); history.Title = Title; history.Url = WebView.Address; string json = File.ReadAllText(StaticDeclarations.Historypath); List <HistItem> histories = JsonConvert.DeserializeObject <List <HistItem> >(json); histories.Add(history); string newJson = JsonConvert.SerializeObject(histories); File.WriteAllText(StaticDeclarations.Historypath, newJson); LastWebsite = WebView.Address; } } } catch (Exception ex) { Console.WriteLine("Write history error: " + ex.Message + " " + ex.Data); } try { foreach (TabView page in mainWindow.Pages) { Task.Factory.StartNew(page.LoadSuggestions); } } catch (Exception ex) { Console.WriteLine("Load suggestions in each TabView error: " + ex.Message + " " + ex.Data); } } })); }
public async Task WriteHistory() { await Dispatcher.BeginInvoke((Action) (() => { if (!StaticDeclarations.IsIncognito) { try { if (!LastWebsite.Equals(WebView.Address)) { if (!System.IO.File.Exists(StaticDeclarations.Historypath)) { var history = new HistItem(); history.Title = Title; history.Url = WebView.Address; var histories = new List<HistItem>(); histories.Add(history); var newJson = JsonConvert.SerializeObject(histories); File.WriteAllText(StaticDeclarations.Historypath, newJson); LastWebsite = WebView.Address; } else { HistItem history = new HistItem(); history.Title = Title; history.Url = WebView.Address; string json = File.ReadAllText(StaticDeclarations.Historypath); List<HistItem> histories = JsonConvert.DeserializeObject<List<HistItem>>(json); histories.Add(history); string newJson = JsonConvert.SerializeObject(histories); File.WriteAllText(StaticDeclarations.Historypath, newJson); LastWebsite = WebView.Address; } } } catch (Exception ex) { Console.WriteLine("Write history error: " + ex.Message + " " + ex.Data); } try { foreach (TabView page in mainWindow.Pages) { Task.Factory.StartNew(page.LoadSuggestions); } } catch (Exception ex) { Console.WriteLine("Load suggestions in each TabView error: " + ex.Message + " " + ex.Data); } } })); }