mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-11 20:19:24 +08:00
优化了中断功能。
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.Library.Framework.NodeFlow
|
||||
@@ -17,9 +18,11 @@ namespace Serein.Library.Framework.NodeFlow
|
||||
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)
|
||||
@@ -31,11 +34,14 @@ namespace Serein.Library.Framework.NodeFlow
|
||||
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
for (int i = 0; i < count && !NodeRunCts.IsCancellationRequested; i++)
|
||||
{
|
||||
NodeRunCts.Token.ThrowIfCancellationRequested();
|
||||
await Task.Delay(time);
|
||||
|
||||
if (NodeRunCts.IsCancellationRequested) { break; }
|
||||
if (FlowEnvironment.IsGlobalInterrupt)
|
||||
{
|
||||
await FlowEnvironment.GetOrCreateGlobalInterruptAsync();
|
||||
}
|
||||
// 确保对局部变量的引用
|
||||
localAction?.Invoke();
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net45" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user