39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Linq;
|
||
using System.Runtime.CompilerServices;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Threading;
|
||
|
||
namespace ShrlAlgoToolkit.RevitAddins.Common.Controls
|
||
{
|
||
// 用于给外界调用的报告器
|
||
public class ProgressReporter
|
||
{
|
||
private readonly ProgressViewModel _viewModel;
|
||
private DateTime _lastUpdate = DateTime.MinValue;
|
||
|
||
public ProgressReporter(ProgressViewModel viewModel)
|
||
{
|
||
_viewModel = viewModel;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新进度 (自带节流控制,防止频繁更新导致UI卡顿)
|
||
/// </summary>
|
||
public void Report(int current, int total, string message = null)
|
||
{
|
||
// 限制 UI 刷新频率(每 50 毫秒最多刷新一次)
|
||
if ((DateTime.Now - _lastUpdate).TotalMilliseconds < 50 && current != total)
|
||
return;
|
||
|
||
_lastUpdate = DateTime.Now;
|
||
_viewModel.Update(current, total, message);
|
||
}
|
||
|
||
public void ReportMessage(string message) => _viewModel.UpdateMessage(message);
|
||
}
|
||
}
|