修改一些Dispatcher.Invoke为Dispatcher.BeginInvoke

This commit is contained in:
tfarcraw 2026-07-16 22:28:27 +08:00
parent e708eabd6e
commit 715342335f
22 changed files with 150 additions and 133 deletions

View File

@ -1,4 +1,4 @@
#nullable enable
#nullable enable
using System.Collections.Specialized;
using System.ComponentModel;
@ -170,7 +170,7 @@ namespace PLCSharp.Core.Prism
if (dispatcher != null && !dispatcher.CheckAccess())
{
#pragma warning disable VSTHRD001 // 同步事件通知无法 async,与本项目其他 Dispatcher.Invoke 保持一致
dispatcher.Invoke((Action)Raise);
dispatcher.Invoke(Raise);
#pragma warning restore VSTHRD001
}
else

View File

@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Drawing;
using System.Windows;
using System.Windows.Media;
@ -30,53 +30,53 @@ namespace PLCSharp.Core.Tools
PointsQueue.TryDequeue(out PointF point);
Points.Add(point);
}
Application.Current?.Dispatcher.Invoke(delegate
{
WriteableBitmap writeableBitmap = _imgSource;
int width = (int)writeableBitmap.Width;
int height = (int)writeableBitmap.Height;
writeableBitmap.Lock();
using var bitmap = new Bitmap(width, height, writeableBitmap.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, writeableBitmap.BackBuffer);
using Graphics graphics = Graphics.FromImage(bitmap);
graphics.Clear(System.Drawing.Color.Black);
//System.Drawing.FontFamily family = new("微软雅黑");
await Application.Current?.Dispatcher.BeginInvoke(() =>
{
WriteableBitmap writeableBitmap = _imgSource;
int width = (int)writeableBitmap.Width;
int height = (int)writeableBitmap.Height;
writeableBitmap.Lock();
using var bitmap = new Bitmap(width, height, writeableBitmap.BackBufferStride, System.Drawing.Imaging.PixelFormat.Format24bppRgb, writeableBitmap.BackBuffer);
using Graphics graphics = Graphics.FromImage(bitmap);
graphics.Clear(System.Drawing.Color.Black);
//System.Drawing.FontFamily family = new("微软雅黑");
//求最小点,看是否为负;为负则整体偏移
var min_x = Points.Min(p => p.X);
var min_y = Points.Min(p => p.Y);
//求最小点,看是否为负;为负则整体偏移
var min_x = Points.Min(p => p.X);
var min_y = Points.Min(p => p.Y);
var points = Points.ToArray();
if (min_x < 0)
for (int i = 0; i < Points.Count; i++)
{
points[i] = new PointF(Points[i].X - min_x, Points[i].Y);
}
if (min_y < 0)
for (int i = 0; i < Points.Count; i++)
{
points[i] = new(Points[i].X, Points[i].Y - min_y);
}
for (int i = 0; i < Points.Count; i++)
{
points[i] = new(points[i].X + 100, points[i].Y + 100);
}
var max_x = points.Max(p => p.X);
var max_y = points.Max(p => p.Y);
var scalex = max_x / width;
var scaley = max_y / height;
var scale = Math.Max(scaley, scalex);
foreach (var point in points)
{
var points = Points.ToArray();
if (min_x < 0)
for (int i = 0; i < Points.Count; i++)
{
points[i] = new PointF(Points[i].X - min_x, Points[i].Y);
}
if (min_y < 0)
for (int i = 0; i < Points.Count; i++)
{
points[i] = new(Points[i].X, Points[i].Y - min_y);
}
for (int i = 0; i < Points.Count; i++)
{
points[i] = new(points[i].X + 100, points[i].Y + 100);
}
var max_x = points.Max(p => p.X);
var max_y = points.Max(p => p.Y);
var scalex = max_x / width;
var scaley = max_y / height;
var scale = Math.Max(scaley, scalex);
foreach (var point in points)
{
graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.White), new Rectangle((int)(point.X / scale), (int)(point.Y / scale), 1, 1));
graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.White), new Rectangle((int)(point.X / scale), (int)(point.Y / scale), 1, 1));
}
}
graphics.Flush();
writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
writeableBitmap.Unlock();
graphics.Flush();
writeableBitmap.AddDirtyRect(new Int32Rect(0, 0, width, height));
writeableBitmap.Unlock();
});
});
}
}

View File

@ -95,7 +95,7 @@
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImagesPool.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImageToFile .xaml.cs">
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImageToFile.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>

View File

@ -1,4 +1,4 @@
using PLCSharp.Core.Common;
using PLCSharp.Core.Common;
using PLCSharp.Core.Prism;
using PLCSharp.VVMs.Connects.ModbusTcp;
using Prism.Commands;
@ -180,7 +180,7 @@ namespace PLCSharp.VVMs.Connects.ModbusRtu
{
if (Client.LogQueue.TryDequeue(out string log))
{
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new ErrorLog(log));
}));

View File

@ -1,4 +1,4 @@
using DryIoc;
using DryIoc;
using PLCSharp.Core.Common;
using PLCSharp.Core.Prism;
using Prism.Commands;
@ -89,7 +89,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
while (!worker.CancellationPending)
{
Thread.Sleep(10);
Thread.Sleep(100);
if (Client == null) continue;
// 日志轮询
@ -97,7 +97,7 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
{
if (Client.LogQueue.TryDequeue(out string log))
{
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new ErrorLog(log));
}));

View File

@ -1,4 +1,4 @@
using DryIoc;
using DryIoc;
using PLCSharp.Core.Common;
using PLCSharp.Core.Prism;
using Prism.Commands;
@ -193,17 +193,17 @@ namespace PLCSharp.VVMs.Connects.ModbusTcp
while (!worker.CancellationPending)
{
Thread.Sleep(10);
Thread.Sleep(100);
if (Server != null && Server.LogSwitch)
{
if (!Server.LogQueue.IsEmpty)
{
if (Server.LogQueue.TryDequeue(out string log))
{
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
{
Logs.Add(new ErrorLog(log));
}));
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new ErrorLog(log));
}));
}
}
}

View File

@ -1,4 +1,4 @@
using PLCSharp.Core.Common;
using PLCSharp.Core.Common;
using PLCSharp.Core.Prism;
using Prism.Commands;
using Prism.Dialogs;
@ -94,7 +94,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
while (!worker.CancellationPending)
{
Thread.Sleep(10);
Thread.Sleep(100);
if (Client == null) continue;
// 日志轮询
@ -102,7 +102,7 @@ namespace PLCSharp.VVMs.Connects.SerialPort
{
if (Client.LogQueue.TryDequeue(out string log))
{
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new ErrorLog(log));
}));

View File

@ -92,7 +92,7 @@ namespace PLCSharp.VVMs.Connects.Socket
var worker = (BackgroundWorker)sender;
while (!worker.CancellationPending)
{
Thread.Sleep(10);
Thread.Sleep(100);
if (Client != null)
{
@ -102,9 +102,9 @@ namespace PLCSharp.VVMs.Connects.Socket
{
if ((Client as SocketClient).LogQueue.TryDequeue(out string log))
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new(log));
Logs.Add(new ErrorLog(log));
}));
}
}

View File

@ -95,24 +95,21 @@ namespace PLCSharp.VVMs.Connects.Socket
while (!worker.CancellationPending)
{
Thread.Sleep(10);
Thread.Sleep(100);
if (Server != null)
{
for (int i = 0; i < Server.Clients.Count; i++)
{
Server.Clients[i].Online = NetTool.PingIP(Server.Clients[i].IP_SerialPort);
}
if (Server.LogSwitch)
{
if (!(Server as SocketServer).LogQueue.IsEmpty)
{
if ((Server as SocketServer).LogQueue.TryDequeue(out string log))
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Logs.Add(new(log));
Logs.Add(new ErrorLog(log));
}));
}
}

View File

@ -212,9 +212,9 @@ namespace PLCSharp.VVMs.Homepage
get { return _ImgSrc; }
set { SetProperty(ref _ImgSrc, value); }
}
private void Dispatch(Action action)
private static void Dispatch(Action action)
{
Application.Current.Dispatcher.Invoke(action);
_= Application.Current.Dispatcher.BeginInvoke(action);
}
/// <summary>

View File

@ -1,4 +1,4 @@
using OpenCvSharp;
using OpenCvSharp;
using OpenCvSharp.WpfExtensions;
using PLCSharp.Core.Common;
using PLCSharp.Core.Prism;
@ -46,7 +46,7 @@ namespace PLCSharp.VVMs.Vision.Camera
{
SetProperty(ref _ShowMat, value);
if (value == null) return;
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (_ImgSrc != null
&& _ShowMat.Width == _ImgSrc.PixelWidth

View File

@ -21,7 +21,6 @@ using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
@ -53,7 +52,7 @@ namespace PLCSharp.VVMs.Vision
ImageEdit.SetBinding(ImageEdit.ImageSourceProperty, binding);
}
private ImageEdit _ImageEdit;
/// <summary>
@ -78,7 +77,7 @@ namespace PLCSharp.VVMs.Vision
/// </summary>
public override void OnDialogClosed()
{
SelectedVisionFunction.EditImageEdit = null;
SelectedVisionFunction.EditImageEdit = null;
}
#region 视觉流程
@ -121,8 +120,8 @@ namespace PLCSharp.VVMs.Vision
ShowMat = SelectedVisionFunction.Src;
}
private DelegateCommand _Save;
/// <summary>
@ -182,7 +181,7 @@ namespace PLCSharp.VVMs.Vision
ShowMat = SelectedVisionFunction.Src;
}
private DelegateCommand<string> _Manage;
/// <summary>
@ -459,7 +458,7 @@ namespace PLCSharp.VVMs.Vision
SelectVisionFlow.StringParams["Variable"] = value.Name;
}
}
private ImageData _SelectImageData;
/// <summary>
@ -619,7 +618,7 @@ namespace PLCSharp.VVMs.Vision
#endregion
#region 局部图像管理
private DelegateCommand<string> _MatManage;
@ -834,31 +833,31 @@ namespace PLCSharp.VVMs.Vision
{
SetProperty(ref _ShowMat, value);
if (value == null) return;
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
{
try
{
if (_ImgSrc != null
&& _ShowMat.Width == _ImgSrc.PixelWidth
&& _ShowMat.Height == _ImgSrc.PixelHeight
&& _ShowMat.Channels() == _ImgSrc.Format.BitsPerPixel / 8
)
{
WriteableBitmapConverter.ToWriteableBitmap(_ShowMat, _ImgSrc);
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
try
{
if (_ImgSrc != null
&& _ShowMat.Width == _ImgSrc.PixelWidth
&& _ShowMat.Height == _ImgSrc.PixelHeight
&& _ShowMat.Channels() == _ImgSrc.Format.BitsPerPixel / 8
)
{
WriteableBitmapConverter.ToWriteableBitmap(_ShowMat, _ImgSrc);
}
else
{
ImgSrc = WriteableBitmapConverter.ToWriteableBitmap(_ShowMat);
}
}
catch (Exception ex)
{
SendErr($"图像转换失败: {ex.Message}");
}
else
{
ImgSrc = WriteableBitmapConverter.ToWriteableBitmap(_ShowMat);
}
}
catch (Exception ex)
{
SendErr($"图像转换失败: {ex.Message}");
}
}
}));
}));
}
@ -945,7 +944,7 @@ namespace PLCSharp.VVMs.Vision
}
@ -967,7 +966,7 @@ namespace PLCSharp.VVMs.Vision
{
SendInfoDialog("请先获取图片!");
return;
}
}
try
{
@ -1322,9 +1321,9 @@ namespace PLCSharp.VVMs.Vision
SendInfoDialog("标定成功");
}
catch (Exception ex) { SendInfoDialog(ex.Message); }
}
}
private AsyncDelegateCommand _ComputeTwoLineTemplate;
public AsyncDelegateCommand ComputeTwoLineTemplate =>
@ -1906,7 +1905,7 @@ namespace PLCSharp.VVMs.Vision
imageEdit.Draw(crossV);
}
#endregion
#endregion

View File

@ -222,7 +222,11 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
var offVarName = item.StringParams.TryGetValue("CircleOffsetVar", out var ov) && !string.IsNullOrEmpty(ov) ? ov : "找圆_Offset";
var offVar = func.Params.Variables.FirstOrDefault(v => v.Name == offVarName);
if (offVar == null) { offVar = new LocalVariableItem(offVarName, "Pos", new Pos()); System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar)); }
if (offVar == null)
{
offVar = new LocalVariableItem(offVarName, "Pos", new Pos());
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar));
}
offVar.RawValue = new Pos(offX, offY, offR, 0);
}

View File

@ -93,7 +93,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
var inls = RansacInliers(edgePoints, inlierTh);
// 可视化 — 写入 DrawCommands
var cyan = Color.FromArgb(128, 0, 255, 255);
var lime = Color.FromArgb(128, 0, 255, 0);
var magenta = Color.FromArgb(128, 255, 0, 255);
@ -198,7 +198,11 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
var offVarName = item.StringParams.TryGetValue("LineOffsetVar", out var ov) && !string.IsNullOrEmpty(ov) ? ov : "找线_Offset";
var offVar = func.Params.Variables.FirstOrDefault(v => v.Name == offVarName);
if (offVar == null) { offVar = new LocalVariableItem(offVarName, "Pos", new Pos()); System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar)); }
if (offVar == null)
{
offVar = new LocalVariableItem(offVarName, "Pos", new Pos());
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar));
}
offVar.RawValue = new Pos(offsetX, offsetY, 0, offsetAngle);
}
_ = func.RenderDrawAsync();
@ -231,8 +235,10 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
vx /= len; vy /= len;
int cnt = 0;
for (int i = 0; i < n; i++)
{ double dx = points[i].X - points[i1].X, dy = points[i].Y - points[i1].Y;
if (Math.Abs(dx * vy - dy * vx) <= threshold) cnt++; }
{
double dx = points[i].X - points[i1].X, dy = points[i].Y - points[i1].Y;
if (Math.Abs(dx * vy - dy * vx) <= threshold) cnt++;
}
if (cnt > bestCnt) { bestCnt = cnt; bvx = vx; bvy = vy; bx = points[i1].X; by = points[i1].Y; }
}
var result = points.Where(p => Math.Abs((p.X - bx) * bvy - (p.Y - by) * bvx) <= threshold).ToList();

View File

@ -1,6 +1,4 @@
using OpenCvSharp;
using System.Linq;
using System.Windows.Media;
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
{
@ -227,7 +225,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
var rr = new RotatedRect(new Point2f((float)fitCx, (float)fitCy), new Size2f((float)fitW, (float)fitH), (float)fitAngle);
var rrPts = rr.Points();
for (int i = 0; i < 4; i++)
func.DrawCommands.Add(DrawCommand.Line(rrPts[i].X, rrPts[i].Y, rrPts[(i+1)%4].X, rrPts[(i+1)%4].Y, System.Windows.Media.Color.FromArgb(128, 255, 0, 255), 3));
func.DrawCommands.Add(DrawCommand.Line(rrPts[i].X, rrPts[i].Y, rrPts[(i + 1) % 4].X, rrPts[(i + 1) % 4].Y, System.Windows.Media.Color.FromArgb(128, 255, 0, 255), 3));
func.DrawCommands.Add(DrawCommand.FilledCircle(fitCx, fitCy, 4, System.Windows.Media.Color.FromArgb(128, 255, 0, 255)));
// 保存结果
func.Params.ResultDoubles["InlierCount"] = inliers;
@ -272,7 +270,11 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
{
var offsetVarName = item.StringParams.TryGetValue("RectOffsetVar", out var ov) && !string.IsNullOrEmpty(ov) ? ov : "找矩形_Offset";
var offsetVar = func.Params.Variables.FirstOrDefault(v => v.Name == offsetVarName);
if (offsetVar == null) { offsetVar = new LocalVariableItem(offsetVarName, "Pos", new Pos()); System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offsetVar)); }
if (offsetVar == null)
{
offsetVar = new LocalVariableItem(offsetVarName, "Pos", new Pos());
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offsetVar));
}
offsetVar.RawValue = new Pos(offsetX, offsetY, 0, offsetAngle);
}

View File

@ -31,7 +31,10 @@
<TextBox Grid.Column="3" Text="{Binding SelectVisionFlow.DoubleParams[ROITop], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
<TextBlock Grid.Row="1" Margin="3,0" Text="Width" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectVisionFlow.DoubleParams[ROIWidth], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
<TextBlock Grid.Row="1" Grid.Column="2" Margin="3,0" Text="Height" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" Grid.Column="2"
Margin="3,0"
Text="Height"
VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="3" Text="{Binding SelectVisionFlow.DoubleParams[ROIHeight], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
</Grid>
</StackPanel>
@ -89,7 +92,7 @@
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectVisionFlow.DoubleParams[AreaMaxPercent], TargetNullValue=100, UpdateSourceTrigger=LostFocus}" />
</Grid>
</GroupBox>
<!-- 执行结果 -->
<GroupBox Header="执行结果">
<Grid Margin="5">
@ -107,13 +110,15 @@
<TextBox Grid.Column="1" Text="{Binding SelectedVisionFunction.Params.ResultDoubles[ColorAreaPercent], Mode=OneWay, StringFormat={}{0:F1}%}" IsReadOnly="True" Background="#FFF0F0F0" />
<TextBlock Grid.Row="1" Text="颜色像素" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectedVisionFunction.Params.ResultDoubles[ColorPixelCount], Mode=OneWay}" IsReadOnly="True" Background="#FFF0F0F0" />
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding SelectedVisionFunction.Params.ResultDoubles[ColorPixelCount], Mode=OneWay}"
IsReadOnly="True" Background="#FFF0F0F0" />
<TextBlock Grid.Row="2" Text="判定结果" VerticalAlignment="Center" />
<TextBox Grid.Row="2" Grid.Column="1"
Text="{Binding SelectVisionFlow.StringParams[ColorAreaResult], Mode=OneWay, TargetNullValue=—}"
IsReadOnly="True" Background="#FFF0F0F0"
FontWeight="Bold" />
FontWeight="Bold"
IsReadOnly="True" Background="#FFF0F0F0" />
</Grid>
</GroupBox>
</StackPanel>

View File

@ -31,7 +31,10 @@
<TextBox Grid.Column="3" Text="{Binding SelectVisionFlow.DoubleParams[ROITop], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
<TextBlock Grid.Row="1" Margin="3,0" Text="Width" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectVisionFlow.DoubleParams[ROIWidth], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
<TextBlock Grid.Row="1" Grid.Column="2" Margin="3,0" Text="Height" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" Grid.Column="2"
Margin="3,0"
Text="Height"
VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="3" Text="{Binding SelectVisionFlow.DoubleParams[ROIHeight], TargetNullValue=—, UpdateSourceTrigger=LostFocus}" />
</Grid>
</StackPanel>
@ -77,7 +80,7 @@
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectVisionFlow.DoubleParams[AreaMaxPercent], TargetNullValue=100, UpdateSourceTrigger=LostFocus}" />
</Grid>
</GroupBox>
<!-- 执行结果 -->
<GroupBox Header="执行结果">
<Grid Margin="5">
@ -95,13 +98,15 @@
<TextBox Grid.Column="1" Text="{Binding SelectedVisionFunction.Params.ResultDoubles[GrayAreaPercent], Mode=OneWay, StringFormat={}{0:F1}%}" IsReadOnly="True" Background="#FFF0F0F0" />
<TextBlock Grid.Row="1" Text="目标像素" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectedVisionFunction.Params.ResultDoubles[GrayPixelCount], Mode=OneWay}" IsReadOnly="True" Background="#FFF0F0F0" />
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding SelectedVisionFunction.Params.ResultDoubles[GrayPixelCount], Mode=OneWay}"
IsReadOnly="True" Background="#FFF0F0F0" />
<TextBlock Grid.Row="2" Text="判定结果" VerticalAlignment="Center" />
<TextBox Grid.Row="2" Grid.Column="1"
Text="{Binding SelectVisionFlow.StringParams[GrayAreaResult], Mode=OneWay, TargetNullValue=—}"
IsReadOnly="True" Background="#FFF0F0F0"
FontWeight="Bold" />
FontWeight="Bold"
IsReadOnly="True" Background="#FFF0F0F0" />
</Grid>
</GroupBox>
</StackPanel>

View File

@ -64,7 +64,8 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
var offVarName = item.StringParams.TryGetValue("IntersectOffsetVar", out var ov) && !string.IsNullOrEmpty(ov) ? ov : "两线交点_Offset";
var offVar = func.Params.Variables.FirstOrDefault(v => v.Name == offVarName);
if (offVar == null) { offVar = new LocalVariableItem(offVarName, "Pos", new Pos()); System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar)); }
if (offVar == null) { offVar = new LocalVariableItem(offVarName, "Pos", new Pos());
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar)); }
offVar.RawValue = new Pos(offX, offY, 0, offAngle);
}

View File

@ -1,6 +1,5 @@
#nullable enable
#nullable enable
using OpenCvSharp;
using PLCSharp.Core.Common;
using System.Windows.Media;
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
@ -122,8 +121,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
if (existingVar == null)
{
existingVar = new LocalVariableItem(varName, "Barcode", new Barcode(new Pos(), ""));
System.Windows.Application.Current.Dispatcher.Invoke(
() => func.Params.Variables.Add(existingVar));
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(existingVar));
}
existingVar.RawValue = new Barcode(new Pos(boxCX, boxCY, 0, 0), text);
}

View File

@ -43,7 +43,7 @@ namespace PLCSharp.VVMs.Vision
{
SetProperty(ref _ShowMat, value);
if (value == null) return;
System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
_ = System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (_ImgSrc != null
&& _ShowMat.Width == _ImgSrc.PixelWidth