private void OnspawnTimerElapsed(object sender, ElapsedEventArgs e) { if (_random.NextDouble() > .45 && _playgroundObjects.Count(x => x.ObjectType == ObjectType.Enemy) < 5) { //because we add a new enemy to the canvas we have to call the canvas dispatcher _gameView.GameCanvas.Dispatcher.Invoke(() => { _playgroundObjects.Add(_enemyFactory.DrawEnemy(_enemyFactory.LoadEnemy(_playgroundObjects), _gameView.GameCanvas)); }); } }