C3204
2026-01-04 2337f47091dbcc1a681f63fc18d9b8d28ab22296
LB_SmartVision/Forms/Pages/ProcessPage/ProcessControl.cs
@@ -43,6 +43,11 @@
            if (ProcessRunBll != null)
                this.label1.Text = $"总数:{ProcessRunBll.total}";
            this.isClosed = false ;
            var TaskPhotoContinue = Task.Factory.StartNew(() =>
            {
                ThreadCircleRun();
            });
        }
        public void SetTitle(string title)
@@ -72,19 +77,17 @@
                }));
            }
            else
            {
                UserHSmartWindowControl.ClearObj();
            }
        }
        /// <summary>
        /// 异步显示图片
        /// </summary>
        /// <param name="ho_image"></param>
        public void ShowHoImage(HImage ho_image)
        public void ShowHoImage(HObject ho_image)
        {
            string str = this.lblTitle.Text;
            UserHSmartWindowControl.hImage = ho_image;
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action(() =>
@@ -93,9 +96,7 @@
                }));
            }
            else
            {
                this.label1.Text = $"总数:{ProcessRunBll.total}";
            }
        }
        public bool Run(out string msg)
@@ -107,9 +108,7 @@
            }
            if (isCircleRuning || ProcessRunBll.bRuning)
            {
                ProcessRunBll.LogInfo($"{ProcessRunBll.Name}正在运行", LogInfoType.ERROR);
            }
            ProcessRunBll.Run();
@@ -126,19 +125,15 @@
                try
                {
                    if (ProcessRunBll == null)
                    {
                        return;
                    }
                    ProcessRunBll.LogInfo(string.Format("流程[{0}]开始运行", this.ProcessRunBll.Name), LogInfoType.INFO);
                    ClearObj();
                    result = Run(out msg);
                    if (ProcessRunBll.GetImage(_Layout, out _, out HImage RecordImage))
                    {
                    if (ProcessRunBll.GetImage(_Layout, out _, out HObject RecordImage))
                        ShowHoImage(RecordImage);
                    }
                }
                catch { msg = "运行出现了异常"; }
@@ -159,37 +154,36 @@
                if (isCircleRuning)
                {
                    threadCircleRun = new Thread(ThreadCircleRun);
                    threadCircleRun.IsBackground = true;
                    threadCircleRun.Start();
                    this.mAutoResetEvent.Set();
                }
                else
                {
                    isCircleRuning = false;
                    //threadCircleRun.Abort();
                }
                if (!isCircleRuning)
                {
                    ProcessRunBll.LogInfo($"{ProcessRunBll.Name}关闭连续运行", LogInfoType.PASS);
                    return;
                }
                ProcessRunBll.LogInfo($"{ProcessRunBll.Name}开启连续运行", LogInfoType.WARN);
            }
            catch { }
        }
        Thread threadCircleRun = null;
        private AutoResetEvent mAutoResetEvent = new AutoResetEvent(false);
        bool isClosed = false;
        void ThreadCircleRun()
        {
            if (!isCircleRuning)
            while (!isClosed)
            {
                ProcessRunBll.LogInfo($"{ProcessRunBll.Name}关闭连续运行", LogInfoType.PASS);
                return;
            }
            ProcessRunBll.LogInfo($"{ProcessRunBll.Name}开启连续运行", LogInfoType.WARN);
            while (isCircleRuning)
            {
                //this.BeginInvoke(new Action(() =>
                //{
                try
                {
                    if (isCircleRuning == false)
                    {
                        this.mAutoResetEvent.WaitOne();
                    }
                    ProcessRunBll.LogInfo($"{ProcessRunBll.Name}开始运行", LogInfoType.WARN);
                    ClearObj();
                    bool result = ProcessRunBll.Run();
@@ -198,14 +192,10 @@
                    ProcessRunBll.LogInfo($"{ProcessRunBll.Name}运行结束,结果为:{msg}"
                        , result ? LogInfoType.PASS : LogInfoType.ERROR);
                    if (ProcessRunBll.GetImage(_Layout, out _, out HImage RecordImage))
                    {
                    if (ProcessRunBll.GetImage(_Layout, out _, out HObject RecordImage))
                        ShowHoImage(RecordImage);
                    }
                }
                catch { }
                //}));
                Thread.Sleep(33);
            }
        }