使用emit代替表达式树构造委托。

内置了websocket server与相应的导航功能,可在实例工程中找到相应的实现。
This commit is contained in:
fengjiayi
2024-10-10 10:45:53 +08:00
parent 0bab770f0a
commit d1b9a3f28f
43 changed files with 1953 additions and 392 deletions

View File

@@ -16,37 +16,37 @@ namespace Serein.Library.Core.NodeFlow
}
public NodeRunCts NodeRunCts { get; set; }
//public ISereinIOC SereinIoc { get; }
// public NodeRunCts NodeRunCts { get; set; }
// public ISereinIOC SereinIoc { get; }
public IFlowEnvironment Env { get; }
public Task CreateTimingTask(Action action, int time = 100, int count = -1)
{
if (NodeRunCts == null)
{
NodeRunCts = Env.IOC.Get<NodeRunCts>();
}
// 使用局部变量,避免捕获外部的 `action`
Action localAction = action;
//public Task CreateTimingTask(Action action, int time = 100, int count = -1)
//{
// if (NodeRunCts == null)
// {
// NodeRunCts = Env.IOC.Get<NodeRunCts>();
// }
// // 使用局部变量,避免捕获外部的 `action`
// Action localAction = action;
return Task.Run(async () =>
{
for (int i = 0; i < count && !NodeRunCts.IsCancellationRequested; i++)
{
await Task.Delay(time);
if (NodeRunCts.IsCancellationRequested) { break; }
//if (FlowEnvironment.IsGlobalInterrupt)
//{
// await FlowEnvironment.GetOrCreateGlobalInterruptAsync();
//}
// 确保对局部变量的引用
localAction?.Invoke();
}
// return Task.Run(async () =>
// {
// for (int i = 0; i < count && !NodeRunCts.IsCancellationRequested; i++)
// {
// await Task.Delay(time);
// if (NodeRunCts.IsCancellationRequested) { break; }
// //if (FlowEnvironment.IsGlobalInterrupt)
// //{
// // await FlowEnvironment.GetOrCreateGlobalInterruptAsync();
// //}
// // 确保对局部变量的引用
// localAction?.Invoke();
// }
// 清理引用,避免闭包导致的内存泄漏
localAction = null;
});
}
// // 清理引用,避免闭包导致的内存泄漏
// localAction = null;
// });
//}
}