diff --git a/src/BreCalClient/MainWindow.xaml.cs b/src/BreCalClient/MainWindow.xaml.cs index 2385ce6..19687bc 100644 --- a/src/BreCalClient/MainWindow.xaml.cs +++ b/src/BreCalClient/MainWindow.xaml.cs @@ -472,45 +472,56 @@ namespace BreCalClient } } - if (shipcalls != null) + try { - foreach (Shipcall shipcall in shipcalls) - { - // load times for each shipcall - List currentTimes = await _timesApi.TimesGetAsync(shipcall.Id); - if(!_allShipcallsDict.ContainsKey(shipcall.Id)) + if (shipcalls != null) + { + foreach (Shipcall shipcall in shipcalls) { - // add entry - ShipcallControlModel scm = new() + // load times for each shipcall + List currentTimes = await _timesApi.TimesGetAsync(shipcall.Id); + + if (!_allShipcallsDict.ContainsKey(shipcall.Id)) { - Shipcall = shipcall, - Times = currentTimes - }; - this.AddShipcall(scm); + // add entry + ShipcallControlModel scm = new() + { + Shipcall = shipcall, + Times = currentTimes + }; + this.AddShipcall(scm); + } + else + { + // update entry + _allShipcallsDict[shipcall.Id].Shipcall = shipcall; + _allShipcallsDict[shipcall.Id].Times = currentTimes; + UpdateShipcall(_allShipcallsDict[shipcall.Id]); + } } - else + + List existingIds = new(this._allShipcallsDict.Keys); + + foreach (int existingId in existingIds) { - // update entry - _allShipcallsDict[shipcall.Id].Shipcall = shipcall; - _allShipcallsDict[shipcall.Id].Times = currentTimes; - UpdateShipcall(_allShipcallsDict[shipcall.Id]); + if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result + { + this.RemoveShipcall(existingId); + } } + + this.FilterShipcalls(); + await uiLock.WaitAsync(); + this.UpdateUI(); } - - List existingIds = new(this._allShipcallsDict.Keys); - - foreach (int existingId in existingIds) - { - if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result - { - this.RemoveShipcall(existingId); - } - } - - this.FilterShipcalls(); - await uiLock.WaitAsync(); - this.UpdateUI(); + } + catch(Exception ex) + { + _log.Error(ex); + } + finally + { uiLock.Release(); }