using Serein.Library.Api; using Serein.Library.Utils; using System; using System.Threading.Tasks; namespace Serein.Library.Framework.NodeFlow { /// /// 动态流程上下文 /// public class DynamicContext : IDynamicContext { public DynamicContext(ISereinIoc sereinIoc, IFlowEnvironment flowEnvironment) { SereinIoc = sereinIoc; FlowEnvironment = flowEnvironment; } public NodeRunCts NodeRunCts { get; set; } public ISereinIoc SereinIoc { get; } public IFlowEnvironment FlowEnvironment { get; } public Task CreateTimingTask(Action action, int time = 100, int count = -1) { if(NodeRunCts == null) { NodeRunCts = SereinIoc.GetOrInstantiate(); } return Task.Factory.StartNew(async () => { for (int i = 0; i < count; i++) { NodeRunCts.Token.ThrowIfCancellationRequested(); await Task.Delay(time); action.Invoke(); } }); } } }