Ejemplo n.º 1
0
        /// <summary>
        /// Kills a thread and invokes a event to allow you to react acordingly
        /// </summary>
        /// <param name="Reason"></param>
        protected internal virtual void Kill(string Reason = DefualtKillReason)
        {
            //kill the exe if it has yet to end
            lock (PrimaryGameExe)
                if (!PrimaryGameExe.HasExited)
                {
                    PrimaryGameExe?.Kill();
                }

            //kill the optional exe's
            foreach (InstanceOptionalExe exe in OptionalExes)
            {
                lock (OptionalExes)
                    if (!exe.OptionalExe.HasExited)
                    {
                        exe?.Kill();
                    }
            }
            //mark as dead and rest timers
            Timer.Stop();
            GameEndedEventArgs EndData = new GameEndedEventArgs()
            {
                GameName = PrimaryGameExe.StartInfo.FileName, Reason = Reason, AllowedTimeInMS = (ulong)Timer.ElapsedMilliseconds
            };

            Timer.Reset();
            //call reacting code
            if (IsAlive)
            {
                GameHasEndedEvent?.Invoke(this, EndData);
            }
            IsAlive = false;
        }
 /// <summary>
 /// simply an internal invoke to chain events to the outside
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GameEndedEventChain(object sender, GameEndedEventArgs e)
 {
     try
     {
         GameHasEndedEvent?.Invoke(sender, e);
     }
     catch
     {}
 }