private void ThreadExecuteFile(LuaApiRegister luaHelper, string luaFileName)
        {
            int originalKillCount = 0;

            try
            {
                originalKillCount = Int32.Parse(Config.Items["Protector"]);
            }
            catch
            {
            }

            _doFileThread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    _throwMessage = "";
                    _returnCode   = null;
                    luaHelper.ExecuteFile(luaFileName);
                }
                catch (ThreadAbortException threadAbortEx)
                {
                    Logger.Info("脚本引擎主动中止线程。");
                }
                catch (SFReturnCode returnCode)
                {
                    _returnCode = returnCode;
                }
                catch (Exception ex)
                {
                    _throwMessage = ex.Message;
                }
            }));
            _doFileThread.IsBackground = true;
            _doFileThread.Start();

            ThreadProtecter.getInstance(originalKillCount).Start(_doFileThread);
            if (ThreadProtecter.getInstance(originalKillCount).IsTimeout)
            {
                Logger.Error("自动关闭脚本");
                throw new TimeoutException("自动关闭脚本");
            }
            else if (_returnCode != null)
            {
                throw _returnCode;
            }
            else if (string.IsNullOrEmpty(_throwMessage))
            {
                Logger.Info("执行完毕:" + luaFileName);
            }
            else if (!string.IsNullOrEmpty(_throwMessage))
            {
                Logger.Info(_throwMessage);
            }
        }
Example #2
0
 public void StayAlive(int killCount)
 {
     ThreadProtecter.getInstance().KillCount = killCount;
 }