private Task UpdateDisplay(int x, int y) { return(Task.Run(() => { try { _isUpdateting = true; var mapDataUpdate = _mapLoader.ActualizeMap(x, y, _mapData); if (mapDataUpdate.LoadedChunks.Any() || mapDataUpdate.UnloadedChunks.Any()) { PhysicalEngine.Instance.DeclareMapData(_mapData); int recycledCount = 0; foreach (var loadedChunk in mapDataUpdate.LoadedChunks) { var chunk = new Chunk(loadedChunk); _chunksContainer.AddContent(chunk); _chunks.Add(chunk); } foreach (var unloadedChunk in mapDataUpdate.UnloadedChunks) { var chunk = _chunks.FirstOrDefault(c => c.ChunkData == unloadedChunk); if (chunk != null) { _chunksContainer.RemoveContentContent(chunk); _chunks.Remove(chunk); //_logger.Log($"Removed chunk at X:{chunk.X} Y:{chunk.Y}"); } } _isUpdateting = false; } } catch (Exception e) { _logger.Log($"Failed to Update Display : {e.Message}"); _isUpdateting = false; } _isUpdateting = false; })); }