avoid thread termination by catching exception thrown on failed times GET

This commit is contained in:
Daniel Schick 2024-05-14 17:53:53 +02:00
parent 5bf5a2c8fa
commit dd61368233

View File

@ -472,45 +472,56 @@ namespace BreCalClient
} }
} }
if (shipcalls != null) try
{ {
foreach (Shipcall shipcall in shipcalls)
{
// load times for each shipcall
List<Times> currentTimes = await _timesApi.TimesGetAsync(shipcall.Id);
if(!_allShipcallsDict.ContainsKey(shipcall.Id)) if (shipcalls != null)
{
foreach (Shipcall shipcall in shipcalls)
{ {
// add entry // load times for each shipcall
ShipcallControlModel scm = new() List<Times> currentTimes = await _timesApi.TimesGetAsync(shipcall.Id);
if (!_allShipcallsDict.ContainsKey(shipcall.Id))
{ {
Shipcall = shipcall, // add entry
Times = currentTimes ShipcallControlModel scm = new()
}; {
this.AddShipcall(scm); 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<int> existingIds = new(this._allShipcallsDict.Keys);
foreach (int existingId in existingIds)
{ {
// update entry if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result
_allShipcallsDict[shipcall.Id].Shipcall = shipcall; {
_allShipcallsDict[shipcall.Id].Times = currentTimes; this.RemoveShipcall(existingId);
UpdateShipcall(_allShipcallsDict[shipcall.Id]); }
} }
this.FilterShipcalls();
await uiLock.WaitAsync();
this.UpdateUI();
} }
}
List<int> existingIds = new(this._allShipcallsDict.Keys); catch(Exception ex)
{
foreach (int existingId in existingIds) _log.Error(ex);
{ }
if (shipcalls.Find(s => s.Id == existingId) == null) // the model is no longer in the search result finally
{ {
this.RemoveShipcall(existingId);
}
}
this.FilterShipcalls();
await uiLock.WaitAsync();
this.UpdateUI();
uiLock.Release(); uiLock.Release();
} }