Пример #1
0
        private void FastDeathButtonClicked(object?sender, EventArgs e)
        {
            var endOfLifeEvent = new EndOfLifeEvent();

            _logService.Log(endOfLifeEvent);

            var survivalModule = _sectorUiState.ActiveActor.Actor.Person.GetModule <ISurvivalModule>();

            survivalModule.SetStatForce(SurvivalStatType.Health, 0);
        }
        /// <summary>
        /// Unblocks waiting threads and ends the execution lifetime.
        /// </summary>
        /// <exception cref="ObjectDisposedException">
        /// The object is disposed.
        /// </exception>
        public void End()
        {
            using (var controlToken = StateControl.Enter())
            {
                RejectIfDisposed();

                if (IsAlive)
                {
                    EndOfLifeEvent.Set();
                    IsAlive = false;
                }
            }
        }
        /// <summary>
        /// Blocks the current thread until <see cref="End" /> or <see cref="Dispose" /> is invoked.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// The service execution lifetime has ended.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The object is disposed.
        /// </exception>
        public void KeepAlive()
        {
            using (var controlToken = StateControl.Enter())
            {
                RejectIfDisposed();

                if (IsAlive == false)
                {
                    throw new InvalidOperationException("The service execution lifetime has ended.");
                }
            }

            EndOfLifeEvent.WaitOne();
        }
        /// <summary>
        /// Releases all resources consumed by the current <see cref="ServiceExecutionLifetime" />.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether or not managed resources should be released.
        /// </param>
        protected override void Dispose(Boolean disposing)
        {
            try
            {
                if (disposing)
                {
                    using (var controlToken = StateControl.Enter())
                    {
                        if (IsAlive)
                        {
                            EndOfLifeEvent.Set();
                            IsAlive = false;
                        }

                        EndOfLifeEvent.Dispose();
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Пример #5
0
        private async Task StartInternalAsync(IGlobe globe, IAutoplayContext context)
        {
            var iterationCounter = 1;

            while (await context.CheckNextIterationAsync() && iterationCounter <= ITERATION_LIMIT)
            {
                for (var updateCounter = 0; updateCounter < GlobeMetrics.OneIterationLength; updateCounter++)
                {
                    try
                    {
                        await globe.UpdateAsync(CancellationToken.None).ConfigureAwait(false);
                    }
                    catch (ActorTaskExecutionException exception)
                    {
                        CatchActorTaskExecutionException(exception);
                    }
                    catch (AggregateException exception)
                    {
                        CatchException(exception.InnerException);
                        throw;
                    }
                }

                iterationCounter++;
            }

            if (iterationCounter >= ITERATION_LIMIT)
            {
                if (PlayerEventLogService != null)
                {
                    var endOfLifeEvent = new EndOfLifeEvent();
                    PlayerEventLogService.Log(endOfLifeEvent);
                }
            }

            ProcessEnd();
        }