public void UpdateCurrentStockInfo(int sid) { lock (this) { CurrentStockInfo = StockInfoList.First(s => s.StockId == sid); } }
private void SortStockInfoList() { if (CurrentStockInfo != null) { StockInfoList = StockInfoList.OrderByDescending(x => x.StockId == CurrentStockInfo.StockId) .ThenBy(x => x.StockId).ToList(); } else { StockInfoList = StockInfoList.OrderBy(x => x.StockId).ToList(); } }
private async Task Update() { var t = RefreshTimeSpan; try { while (true) { var addlist = new List <StockInfo>(); var deletelist = new List <StockInfo>(); var s = _stockAgent.GetAllStocks(); lock (this) { s.ForEach(x => { var ss = StockInfoList.FirstOrDefault(y => y.StockId == x.StockId); if (ss != null) { ss.Update(x); } else { var si = new StockInfo(); si.Create(_stockAgent.GetStock(x.StockId, DateTime.Now)); si.Update(x); addlist.Add(si); } }); StockInfoList.ForEach(x => { var ss = s.FirstOrDefault(y => y.StockId == x.StockId); if (ss == null) { deletelist.Add(x); } }); addlist.ForEach(x => StockInfoList.Add(x)); deletelist.ForEach(x => StockInfoList.Remove(x)); SortStockInfoList(); } await Task.Delay(t); } } catch (Exception e) { await _dialogService.ShowError(e, "错误", "确定", null); } }