Beispiel #1
0
        private void SyncSimulations()
        {
            simulationProgress.Text = "Simulations started";

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            for (int i = 1; i <= _gameAmount; i++)
            {
                DataCollector dataCollector = new DataCollector(_playerAmount);
                dataCollector.SimulationComplete += SaveMoves;
                dataCollector.Start();
            }
            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            UpdateTimer(ts);

            simulationProgress.Text = "Simulations finished - saving results to the database";
            DataAccess.SaveGameData(_gameResults);
            _gameResults.Clear();
            UpdateRecordCount();
            simulationProgress.Text = "Done";
        }
Beispiel #2
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);
            }
        }