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