示例#1
0
 private static void runTigger()
 {
     try
     {
         while (true)
         {
             Task.Delay(1).Wait();
             if (tokenSource.IsCancellationRequested)
             {
                 return;
             }
             if (toRun.Count > 0)
             {
                 try
                 {
                     lua.Global.Get <XLua.LuaFunction>("tiggerCB").Call(toRun[0].id, toRun[0].type, toRun[0].data);
                 }
                 catch (Exception le)
                 {
                     LuaApi.PrintLog("回调报错:\r\n" + le.Message);
                 }
                 if (tokenSource.IsCancellationRequested)
                 {
                     return;
                 }
                 toRun.RemoveAt(0);
             }
         }
     }
     catch (Exception ex)
     {
         StopLua(ex.ToString());
     }
 }
示例#2
0
 /// <summary>
 /// 停止运行lua
 /// </summary>
 public static void StopLua(string ex)
 {
     LuaRunError(null, EventArgs.Empty);
     if (ex != "")
     {
         LuaApi.PrintLog("lua代码报错了:\r\n" + ex);
     }
     else
     {
         LuaApi.PrintLog("lua代码已停止");
     }
     foreach (var v in pool)
     {
         v.Value.Cancel();
     }
     isRunning = false;
     tokenSource.Cancel();
     pool.Clear();
     lua = null;
 }