コード例 #1
0
        public IHttpActionResult Put()
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var simulationRunner = new SimulationRunner(GameConstants.GridSize, GameConstants.GridSize,
                                                        cancellationTokenSource.Token);

            var simulationRunnerHolder = new SimulationRunnerHolder(simulationRunner, cancellationTokenSource);

            simulationRunnerHolder.LastActiveGet = DateTime.Now;
            simulationRunnerHolder.StartNewRun();

            var gameId = Guid.NewGuid().ToString();

            HttpContext.Current.Application.Add(gameId, simulationRunnerHolder);

            // timer task to check that the research is alive, if not shut it down
            var timer = new System.Timers.Timer();

            timer.Elapsed  += (sender, e) => TimerWorker(sender, e, simulationRunnerHolder, gameId);
            timer.Interval  = 5000;
            timer.Enabled   = true;
            timer.AutoReset = true;
            timer.Start();

            return(Ok(gameId));
        }