public void Close() { _levelTicker.Change(Timeout.Infinite, Timeout.Infinite); WaitHandle waitHandle = new AutoResetEvent(false); _levelTicker.Dispose(waitHandle); WaitHandle.WaitAll(new[] { waitHandle }, TimeSpan.FromMinutes(2)); _levelTicker = null; foreach (var entity in Entities.Values.ToArray()) { entity.DespawnEntity(); } Entities.Clear(); foreach (Player player in Players.Values.ToArray()) { player.Disconnect("Unexpected player lingering on close of level: " + player.Username); } Players.Clear(); BlockEntities.Clear(); BlockWithTicks.Clear(); BlockWithTicks = null; BlockEntities = null; Players = null; Entities = null; _worldProvider = null; Log.Info("Closed level: " + LevelId); }
public void Close() { //_levelTicker.Change(Timeout.Infinite, Timeout.Infinite); //WaitHandle waitHandle = new AutoResetEvent(false); //_levelTicker.Dispose(waitHandle); //WaitHandle.WaitAll(new[] {waitHandle}, TimeSpan.FromMinutes(2)); //_levelTicker = null; _tickerHighPrecisionTimer.Dispose(); foreach (var entity in Entities.Values.ToArray()) { entity.DespawnEntity(); } Entities.Clear(); foreach (Player player in Players.Values.ToArray()) { player.Disconnect("Unexpected player lingering on close of level: " + player.Username); } Players.Clear(); BlockEntities.Clear(); BlockWithTicks.Clear(); BlockWithTicks = null; BlockEntities = null; Players = null; Entities = null; AnvilWorldProvider provider = _worldProvider as AnvilWorldProvider; if (provider != null) { foreach (var chunk in provider._chunkCache) { chunk.Value?.ClearCache(); } } _worldProvider = null; Log.Info("Closed level: " + LevelId); }