Beispiel #1
0
        /// <summary>
        /// the thread loop
        /// </summary>
        /// <param name="tokenObj"></param>
        protected void ThreadLoop(object tokenObj)
        {
            DateTime startedAt;

            CgTimeStampSource.Calibrate();
            if (tokenObj is CancellationToken token && _status.TrySetStarting())
            {
                startedAt = CgTimeStampSource.Now;
                try
                {
                    DoJob(token);
                }
                catch (OperationCanceledException)
                {
                    _status.TrySetCancelRequested();
                }
                catch (Exception ex)
                {
                    Fault = ex;
                }
                finally
                {
                    try
                    {
                        PerformFinishingActions();
                    }
                    catch (Exception ex)
                    {
                        FinishingFault = ex;
                    }

                    _status.ForceEnded();
                    DateTime ts       = CgTimeStampSource.Now;
                    TimeSpan duration = ts - startedAt;
                    _duration.TrySet(duration);
                    _helper.WriteLine("At [" + ts.ToString("O") + "], game thread of type [" + ConcreteType.Name +
                                      "] and thread name [" + _t.Value.Name + "] terminated.  Duration: [" +
                                      duration.TotalMilliseconds.ToString("N3") + "] milliseconds.");
                }
            }
        }