Esempio n. 1
0
 /// <summary>
 /// 多线程处理模块,每个模块单独线程处理任务,单个的把任务放入step队列
 /// </summary>
 /// <param name="block"></param>
 private void ExecBlockMutiThread(FlowBlock block)
 {
     block.IsRunning = true;
     Task.Factory.StartNew(() =>
     {
         Thread.CurrentThread.IsBackground = true;
         block.ExecEvent.Set();//默认打开
         if (block.Steps != null)
         {
             int seq   = 1;
             var watch = new Stopwatch();
             foreach (var step in block.Steps)
             {
                 step.Seq     = seq++;
                 step.Perform = null;
                 if (step.Type != ActionTypes.None)
                 {
                     if (!AddressDict.ContainsKey(step.PlcAddressName))
                     {
                         OnLoged($"[{block.Name}][{step.Seq}]not found PlcAddressName {step.PlcAddressName}");
                         step.Result = Result.Fail();
                         break;
                     }
                     watch.Restart();
                     step.Perform = () => block.ExecEvent.Set();
                     //放入plc执行队列
                     StepQueue.Enqueue(step);
                     //等待放行信号
                     block.ExecEvent.WaitOne();
                     watch.Stop();
                     OnLoged($"[{block.Name}][{step.Seq}][{step.PlcAddressName}]{step.Result.IsSuccess} {step.Result.Msg} 耗时{watch.ElapsedMilliseconds}ms");
                 }
                 if (step.Result.IsSuccess)
                 {
                     if (step.Result.IsSuccess && !step.ActionName.IsNullOrWhiteSpace())
                     {
                         _watchSetp.Restart();
                         //方法的执行结果不影响步骤
                         ActionArgs actionArgs = new ActionArgs
                         {
                             WorkFlowName      = _workFlow.Name,
                             BlockName         = _curBlock.Name,
                             StepSeq           = step.Seq,
                             StepResult        = step.Result,
                             RedisClientLocal  = RedisClientLocal,
                             RedisClientRemote = RedisClientRemote
                         };
                         var res = ActionProx(step.ActionName, _workFlow.ActionTimeOut, actionArgs);
                         _watchSetp.Stop();
                         OnLoged($"[{block.Name}][{step.Seq}][{step.ActionName}]{res.IsSuccess} {res.Msg} 耗时{_watchSetp.ElapsedMilliseconds}ms");
                     }
                 }
             }
         }
         OnLoged($"[{block.Name}]exit");
         block.IsRunning = false;
     });
 }
Esempio n. 2
0
 public void EnqueueBlock(FlowBlock block)
 {
     if (block.IsRunning)
     {
         //如果当前模块正在执行则略过
         OnLoged($"[block] isRuuning");
         return;
     }
     //开始执行模块
     BlockQueue.Enqueue(block);
 }
Esempio n. 3
0
 /// <summary>
 /// 单线程处理模块,每次将所有step都放入队列执行
 /// </summary>
 /// <param name="block"></param>
 private void ExecBlockSingleThread(FlowBlock block)
 {
     _curBlock = block;
     if (_curBlock.Steps != null)
     {
         int seq = 1;
         foreach (var item in _curBlock.Steps)
         {
             item.Seq = seq++;
             StepQueue.Enqueue(item);
         }
     }
 }