Files
2026-02-24 11:34:18 +08:00

30 lines
974 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}