下载耗时太久,异步操作
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
|
||||
@@ -26,6 +26,7 @@ using CapMachine.Model.MeterConfig;
|
||||
using Masuit.Tools;
|
||||
using System.Timers;
|
||||
using Prism.Events;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace CapMachine.Wpf.Services
|
||||
{
|
||||
@@ -51,6 +52,7 @@ namespace CapMachine.Wpf.Services
|
||||
LinDriveService = linDriveService;
|
||||
ProRunChannel = MachineRtDataService.ProRunChannel;
|
||||
LogService = logService;
|
||||
CurDispatcher = Dispatcher.CurrentDispatcher;
|
||||
|
||||
//实例化函数
|
||||
ListProExModel = new List<ProExModel>();
|
||||
@@ -116,6 +118,7 @@ namespace CapMachine.Wpf.Services
|
||||
public CanDriveService CanDriveService { get; }
|
||||
public LinDriveService LinDriveService { get; }
|
||||
public ILogService LogService { get; }
|
||||
public Dispatcher CurDispatcher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 西门子连接驱动程序
|
||||
@@ -163,17 +166,30 @@ namespace CapMachine.Wpf.Services
|
||||
return $"{hours}:{minutes:D2}:{seconds:D2}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否在下载中
|
||||
/// </summary>
|
||||
public bool IsLoadProSeging { get; set; } = false; //是否加载了程序运行集合
|
||||
|
||||
/// <summary>
|
||||
/// 加载选中的程序运行集合
|
||||
/// 目前步骤设置常值,是OK的,但是在斜坡多步骤里面也可以设置 50-50 10秒的常值设置,那么在打点时,上面的两个常值都能识别
|
||||
/// </summary>
|
||||
public void LoadProSegRun(List<ProSegRun> SelectedListProSegRun)
|
||||
public async Task LoadProSegRun(List<ProSegRun> SelectedListProSegRun, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (SelectedListProSegRun == null || SelectedListProSegRun.Count() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//标记下载过程的状态
|
||||
IsLoadProSeging = true;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// 在UI线程上执行必要的UI操作
|
||||
await CurDispatcher.InvokeAsync(() =>
|
||||
{
|
||||
//取消之前的程序执行
|
||||
EndProRun();
|
||||
//先清空之前的步骤数据
|
||||
@@ -181,12 +197,17 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
itemProExModel.ListProStepExe.Clear();
|
||||
itemProExModel.ListSlopExStep.Clear();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
|
||||
//多个选中的程序块循环
|
||||
foreach (var itemProSegRun in SelectedListProSegRun)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
//获取当前程序块
|
||||
//逐个对应的程序
|
||||
var CurProgramSeg = FreeSql.Select<ProgramSeg>(itemProSegRun.ProgramSegId)
|
||||
@@ -3143,6 +3164,18 @@ namespace CapMachine.Wpf.Services
|
||||
|
||||
//通过速度的步骤信息获取总时间
|
||||
ProRunTimeCalcModel.TotalProSec = ListProExModel.FindFirst(a => a.MeterName == "转速").ListProStepExe.Sum(a => a.KeepTime);
|
||||
}, cancellationToken);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
IsLoadProSeging = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoadProSeging = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace CapMachine.Wpf.ViewModels
|
||||
@@ -2324,7 +2325,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
{
|
||||
if (_GenProPlcCmd == null)
|
||||
{
|
||||
_GenProPlcCmd = new DelegateCommand(() => GenProPlcCmdMethod());
|
||||
_GenProPlcCmd = new DelegateCommand(async () => await GenProPlcCmdMethod());
|
||||
}
|
||||
return _GenProPlcCmd;
|
||||
}
|
||||
@@ -2332,17 +2333,23 @@ namespace CapMachine.Wpf.ViewModels
|
||||
/// <summary>
|
||||
/// 生产下载执行方法
|
||||
/// </summary>
|
||||
private void GenProPlcCmdMethod()
|
||||
private async Task GenProPlcCmdMethod()
|
||||
{
|
||||
if (ProSegRunListViewItems != null && ProSegRunListViewItems.Count() > 0)
|
||||
{
|
||||
//当前的程序开始标记
|
||||
//ProParsSongZhiHelper.Start();
|
||||
|
||||
if (ProRuntimeService.IsLoadProSeging)
|
||||
{
|
||||
MessageBox.Show("下载过程中无法操作,请下载完毕后再操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
||||
return;
|
||||
}
|
||||
|
||||
//返回的数据
|
||||
List<PlcParsData> ReturnPlcParsData = new List<PlcParsData>();
|
||||
|
||||
ProRuntimeService.LoadProSegRun(ProSegRunListViewItems.ToList());
|
||||
await ProRuntimeService.LoadProSegRun(ProSegRunListViewItems.ToList(), new CancellationToken());
|
||||
|
||||
////防止上一次下载的程序多余当前的步骤,为了清空多余的步骤数据,增加一行的数据
|
||||
//ReturnPlcParsData = ProParsSongZhiHelper.AddNullData(ReturnPlcParsData);
|
||||
@@ -3198,6 +3205,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
SelectedProStepDto.SpeedCycle!.IsSlop = true;
|
||||
SelectedProStepDto.SpeedCycle!.Cycle = SelectedProStepDto.SpeedCycle.Cycle;
|
||||
|
||||
//计算程序段的总时间
|
||||
SumProSegTime();
|
||||
//if (MeterSpeedExDto.TotalSlopTime != GetKeepTimeBySpeed())
|
||||
//{
|
||||
@@ -3259,6 +3267,7 @@ namespace CapMachine.Wpf.ViewModels
|
||||
|
||||
if (time.Hours > 0)
|
||||
{
|
||||
parts.Add($"{time.Days}天");
|
||||
parts.Add($"{time.Hours}小时");
|
||||
parts.Add($"{time.Minutes}分");
|
||||
parts.Add($"{time.Seconds}秒");
|
||||
|
||||
Reference in New Issue
Block a user