Beispiel #1
0
        private void AsyncSimulations()
        {
            UpdateProgressRing(true);
            UpdateProgress("Simulations started");
            _asyncSimulationCounter = 1;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            _processorCountValue = processorCount.Value;
            int split = _gameAmount / (int)_processorCountValue;

            for (int i = 1; i <= _processorCountValue; i++)
            {
                _ = Windows.System.Threading.ThreadPool.RunAsync(
                    (workItem) =>
                {
                    for (int f = 0; f < split; f++)
                    {
                        DataCollector dataCollector       = new DataCollector(_playerAmount);
                        dataCollector.SimulationComplete += SaveMoves;
                        dataCollector.Start();
                    }

                    if (IsDone())
                    {
                        stopWatch.Stop();
                        // Get the elapsed time as a TimeSpan value.
                        TimeSpan ts = stopWatch.Elapsed;
                        UpdateTimer(ts);
                        UpdateProgress("Simulations finished - saving results to the database");
                        DataAccess.SaveGameData(_gameResults);
                        _gameResults.Clear();
                        UpdateRecordCount();
                        UpdateProgress("Done");
                        UpdateProgressRing(false);
                    }
                }, WorkItemPriority.Low, WorkItemOptions.TimeSliced);
            }
        }