.net 多Task放入一个LIST<Task> Loop

本文探讨了如何在.NET中将多个Task实例添加到List<Task>,然后进行并行执行,提高程序运行效率。通过这种方式,可以利用多核处理器的优势,同时处理多个任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    IList<Task> tasks = new List<Task>();
            while (currentSetp < tracingCount)
            {
                if (tasks.Count(i => i.IsCompleted) > 1)
                {
                    var taskIds = tasks.Where(m => m.IsCompleted).Select(m => m.Id).ToList();
                    foreach (var id in taskIds)
                    {
                        tasks.Remove(tasks.Single(m => m.Id == id));
                    }
                }
                else
                {
                    Task.WaitAny(Task.Delay(1000));
                }

                if (tasks.Count >= 10) continue;
                Console.WriteLine(currentSetp + " passed,Remain:" + (tracingCount - currentSetp) + ",Found:" + report.Count);

                var currentLoop = userTracingDb.Skip(currentSetp).Take(jump);


                foreach (var loop in currentLoop)
                {
                    tasks.Add(Task.Run(() => IpIdentify(loop)));
                }

                currentSetp += jump;

}

<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test"> <signal id="rollbackSignal" name="rollbackSignal"></signal> <process id="test1_1923300107290869761" name="商机立项" isExecutable="true"> <extensionElements> <flowable:executionListener event="start" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> <flowable:executionListener event="end" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> </extensionElements> <startEvent id="Start_1748072983902_x6bm" name="开始"></startEvent> <userTask id="Initiator_1748072985304_x6ka" name="发起人" flowable:assignee="${initiator}"> <extensionElements> <flowable:taskListener event="create" delegateExpression="${submitApplyAutoCompListener}"></flowable:taskListener> </extensionElements> </userTask> <boundaryEvent id="boundaryEvent_Approve_1748073009567_0rhm" attachedToRef="Approve_1748073009567_0rhm" cancelActivity="false"> <signalEventDefinition signalRef="rollbackSignal"></signalEventDefinition> </boundaryEvent> <serviceTask id="multiInst_comp_Approve_1748073009567_0rhm" name="实例补偿任务" isForCompensation="true" flowable:delegateExpression="${sequMultiInstReturnHandler}"></serviceTask> <sequenceFlow sourceRef="boundaryEvent_Approve_1748073009567_0rhm" targetRef="multiInst_comp_Approve_1748073009567_0rhm"></sequenceFlow> <userTask id="Approve_1748073009567_0rhm" name="部门审批" flowable:candidateGroups="1894766265457541122,1894765564253806594"> <extensionElements> <custom:apprType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[2]]></custom:apprType> <custom:emptyAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[3]]></custom:emptyAppr> <custom:isOptional xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[0]]></custom:isOptional> <custom:returnType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[[32, 31]]]></custom:returnType> <custom:promSameAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[1]]></custom:promSameAppr> <flowable:taskListener event="create" delegateExpression="${nodeApprListener}"></flowable:taskListener> <flowable:taskListener event="complete" delegateExpression="${nodeApprListener}"></flowable:taskListener> </extensionElements> <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${candidateGroups}" flowable:elementVariable="approver"> <completionCondition>${canComplete==true && nrOfCompletedInstances>=nrOfInstances}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="End_1748072994507_6koo" name="流程结束"></endEvent> <sequenceFlow id="Edge_1748077535007_b60g" sourceRef="Approve_1748073009567_0rhm" targetRef="End_1748072994507_6koo"></sequenceFlow> <sequenceFlow id="Edge_1748077555219_1t0f" sourceRef="Start_1748072983902_x6bm" targetRef="Initiator_1748072985304_x6ka"></sequenceFlow> <sequenceFlow id="Edge_1751371930339_mw08" sourceRef="Initiator_1748072985304_x6ka" targetRef="Approve_1748073009567_0rhm"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1_1923300107290869761"> <bpmndi:BPMNPlane bpmnElement="test1_1923300107290869761" id="BPMNPlane_test1_1923300107290869761"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>这个配置怎么实现退回上一个办理人
最新发布
08-16
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test"> <signal id="rollbackSignal" name="rollbackSignal"></signal> <process id="test1_1923300107290869761" name="商机立项" isExecutable="true"> <extensionElements> <flowable:executionListener event="start" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> <flowable:executionListener event="end" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> </extensionElements> <startEvent id="Start_1748072983902_x6bm" name="开始"></startEvent> <userTask id="Initiator_1748072985304_x6ka" name="发起人" flowable:assignee="${initiator}"> <extensionElements> <flowable:taskListener event="create" delegateExpression="${submitApplyAutoCompListener}"></flowable:taskListener> </extensionElements> </userTask> <boundaryEvent id="boundaryEvent_Approve_1748073009567_0rhm" attachedToRef="Approve_1748073009567_0rhm" cancelActivity="false"> <signalEventDefinition signalRef="rollbackSignal"></signalEventDefinition> </boundaryEvent> <serviceTask id="multiInst_comp_Approve_1748073009567_0rhm" name="实例补偿任务" isForCompensation="true" flowable:delegateExpression="${sequMultiInstReturnHandler}"></serviceTask> <sequenceFlow sourceRef="boundaryEvent_Approve_1748073009567_0rhm" targetRef="multiInst_comp_Approve_1748073009567_0rhm"></sequenceFlow> <userTask id="Approve_1748073009567_0rhm" name="部门审批" flowable:candidateGroups="1894766265457541122,1894765564253806594"> <extensionElements> <custom:apprType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[2]]></custom:apprType> <custom:emptyAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[3]]></custom:emptyAppr> <custom:isOptional xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[0]]></custom:isOptional> <custom:returnType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[[32, 31]]]></custom:returnType> <custom:promSameAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[1]]></custom:promSameAppr> <flowable:taskListener event="create" delegateExpression="${nodeApprListener}"></flowable:taskListener> <flowable:taskListener event="complete" delegateExpression="${nodeApprListener}"></flowable:taskListener> </extensionElements> <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${candidateGroups}" flowable:elementVariable="approver"> <completionCondition>${canComplete==true && nrOfCompletedInstances>=nrOfInstances}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="End_1748072994507_6koo" name="流程结束"></endEvent> <sequenceFlow id="Edge_1748077535007_b60g" sourceRef="Approve_1748073009567_0rhm" targetRef="End_1748072994507_6koo"></sequenceFlow> <sequenceFlow id="Edge_1748077555219_1t0f" sourceRef="Start_1748072983902_x6bm" targetRef="Initiator_1748072985304_x6ka"></sequenceFlow> <sequenceFlow id="Edge_1751371930339_mw08" sourceRef="Initiator_1748072985304_x6ka" targetRef="Approve_1748073009567_0rhm"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1_1923300107290869761"> <bpmndi:BPMNPlane bpmnElement="test1_1923300107290869761" id="BPMNPlane_test1_1923300107290869761"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>在 Flowable7.1 中实现 串行实例任务 有A、B、C参与者,在某个参与者不同意时退回同一实例的上一个任务,例如B不同意退回A,A同意后继续给B审批,B审批同意给C,C不同意,退回给B
08-14
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test"> <signal id="rollbackSignal" name="rollbackSignal"></signal> <process id="test1_1923300107290869761" name="商机立项" isExecutable="true"> <extensionElements> <flowable:executionListener event="start" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> <flowable:executionListener event="end" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> </extensionElements> <startEvent id="Start_1748072983902_x6bm" name="开始"></startEvent> <userTask id="Initiator_1748072985304_x6ka" name="发起人" flowable:assignee="${initiator}"> <extensionElements> <flowable:taskListener event="create" delegateExpression="${submitApplyAutoCompListener}"></flowable:taskListener> </extensionElements> </userTask> <boundaryEvent id="boundaryEvent_Approve_1748073009567_0rhm" attachedToRef="Approve_1748073009567_0rhm" cancelActivity="false"> <signalEventDefinition signalRef="rollbackSignal"></signalEventDefinition> </boundaryEvent> <serviceTask id="multiInst_comp_Approve_1748073009567_0rhm" name="实例补偿任务" isForCompensation="true" flowable:delegateExpression="${sequMultiInstReturnHandler}"></serviceTask> <sequenceFlow sourceRef="boundaryEvent_Approve_1748073009567_0rhm" targetRef="multiInst_comp_Approve_1748073009567_0rhm"></sequenceFlow> <userTask id="Approve_1748073009567_0rhm" name="部门审批" flowable:candidateGroups="1894766265457541122,1894765564253806594"> <extensionElements> <custom:apprType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[2]]></custom:apprType> <custom:emptyAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[3]]></custom:emptyAppr> <custom:isOptional xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[0]]></custom:isOptional> <custom:returnType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[[32, 31]]]></custom:returnType> <custom:promSameAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[1]]></custom:promSameAppr> <flowable:taskListener event="create" delegateExpression="${nodeApprListener}"></flowable:taskListener> <flowable:taskListener event="complete" delegateExpression="${nodeApprListener}"></flowable:taskListener> </extensionElements> <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${candidateGroups}" flowable:elementVariable="approver"> <completionCondition>${canComplete==true && nrOfCompletedInstances>=nrOfInstances}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="End_1748072994507_6koo" name="流程结束"></endEvent> <sequenceFlow id="Edge_1748077535007_b60g" sourceRef="Approve_1748073009567_0rhm" targetRef="End_1748072994507_6koo"></sequenceFlow> <sequenceFlow id="Edge_1748077555219_1t0f" sourceRef="Start_1748072983902_x6bm" targetRef="Initiator_1748072985304_x6ka"></sequenceFlow> <sequenceFlow id="Edge_1751371930339_mw08" sourceRef="Initiator_1748072985304_x6ka" targetRef="Approve_1748073009567_0rhm"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1_1923300107290869761"> <bpmndi:BPMNPlane bpmnElement="test1_1923300107290869761" id="BPMNPlane_test1_1923300107290869761"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
08-16
在 Flowable7.1 中实现 串行实例任务 有A、B、C参与者,在某个参与者不同意时退回同一实例的上一个任务,例如B不同意退回A,A同意后继续给B审批,B审批同意给C,C不同意,退回给B。配置文件如下:<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test"> <process id="test1_1923300107290869761" name="商机立项" isExecutable="true"> <extensionElements> <flowable:executionListener event="start" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> <flowable:executionListener event="end" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> </extensionElements> <startEvent id="Start_1748072983902_x6bm" name="开始"></startEvent> <userTask id="Initiator_1748072985304_x6ka" name="发起人" flowable:assignee="${initiator}"> <extensionElements> <flowable:taskListener event="create" delegateExpression="${submitApplyAutoCompListener}"></flowable:taskListener> </extensionElements> </userTask> <userTask id="Approve_1748073009567_0rhm" name="部门审批" flowable:candidateGroups="1894766265457541122,1894765564253806594"> <extensionElements> <custom:apprType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[2]]></custom:apprType> <custom:emptyAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[3]]></custom:emptyAppr> <custom:isOptional xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[0]]></custom:isOptional> <custom:returnType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[[32, 31]]]></custom:returnType> <custom:promSameAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[1]]></custom:promSameAppr> <flowable:taskListener event="create" delegateExpression="${nodeApprListener}"></flowable:taskListener> <flowable:taskListener event="complete" delegateExpression="${nodeApprListener}"></flowable:taskListener> </extensionElements> <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${candidateGroups}" flowable:elementVariable="approver"> <completionCondition>${canComplete==true && nrOfCompletedInstances>=nrOfInstances}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="End_1748072994507_6koo" name="流程结束"></endEvent> <sequenceFlow id="Edge_1748077535007_b60g" sourceRef="Approve_1748073009567_0rhm" targetRef="End_1748072994507_6koo"></sequenceFlow> <sequenceFlow id="Edge_1748077555219_1t0f" sourceRef="Start_1748072983902_x6bm" targetRef="Initiator_1748072985304_x6ka"></sequenceFlow> <sequenceFlow id="Edge_1751371930339_mw08" sourceRef="Initiator_1748072985304_x6ka" targetRef="Approve_1748073009567_0rhm"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1_1923300107290869761"> <bpmndi:BPMNPlane bpmnElement="test1_1923300107290869761" id="BPMNPlane_test1_1923300107290869761"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值