From 771a0e7b6b1276087515bbe94de28358cb92963b Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 04 六月 2026 10:32:27 +0800
Subject: [PATCH] 优化老化;
---
HMI.UI/Util/ToastHelper.cs | 78 ++++++++++++++++++++++----------------
1 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/HMI.UI/Util/ToastHelper.cs b/HMI.UI/Util/ToastHelper.cs
index 90a409b..b578a76 100644
--- a/HMI.UI/Util/ToastHelper.cs
+++ b/HMI.UI/Util/ToastHelper.cs
@@ -1,6 +1,6 @@
锘縰sing HMI.Core.Util;
using Panuon.WPF.UI;
-using System.Runtime.CompilerServices;
+using System;
using System.Windows;
using System.Windows.Controls;
@@ -47,15 +47,18 @@
ToastPosition position = ToastPosition.Top, double offset = 0, int durationMs = 3000,
ToastWindow targetWindow = ToastWindow.ActiveWindow)
{
- var window = Application.Current.MainWindow;
- if (window is WindowX)
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
- Instance.Success(window, message, icon, position, offset, durationMs, targetWindow);
- }
- else
- {
- MessageBox.Show(message, LangUtil.Get("App.Success"));
- }
+ var window = Application.Current.MainWindow;
+ if (window is WindowX)
+ {
+ Instance.Success(window, message, icon, position, offset, durationMs, targetWindow);
+ }
+ else
+ {
+ MessageBox.Show(message, LangUtil.Get("App.Success"));
+ }
+ }));
}
public static void Warning(string message,
@@ -63,15 +66,18 @@
ToastPosition position = ToastPosition.Top, double offset = 0, int durationMs = 3000,
ToastWindow targetWindow = ToastWindow.ActiveWindow)
{
- var window = Application.Current.MainWindow;
- if (window is WindowX)
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
- Instance.Warning(window, message, icon, position, offset, durationMs, targetWindow);
- }
- else
- {
- MessageBox.Show(message, LangUtil.Get("App.Warn"));
- }
+ var window = Application.Current.MainWindow;
+ if (window is WindowX)
+ {
+ Instance.Warning(window, message, icon, position, offset, durationMs, targetWindow);
+ }
+ else
+ {
+ MessageBox.Show(message, LangUtil.Get("App.Warn"));
+ }
+ }));
}
public static void Error(string message,
@@ -79,16 +85,19 @@
ToastPosition position = ToastPosition.Top, double offset = 0, int durationMs = 3000,
ToastWindow targetWindow = ToastWindow.ActiveWindow)
{
- var window = Application.Current.MainWindow;
- if (window is WindowX)
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
+ var window = Application.Current.MainWindow;
+ if (window is WindowX)
+ {
- Instance.Error(window, message, icon, position, offset, durationMs, targetWindow);
- }
- else
- {
- MessageBox.Show(message, LangUtil.Get("App.Error"));
- }
+ Instance.Error(window, message, icon, position, offset, durationMs, targetWindow);
+ }
+ else
+ {
+ MessageBox.Show(message, LangUtil.Get("App.Error"));
+ }
+ }));
}
public static void Info(string message,
@@ -96,16 +105,19 @@
ToastPosition position = ToastPosition.Top, double offset = 0, int durationMs = 3000,
ToastWindow targetWindow = ToastWindow.ActiveWindow)
{
- var window = Application.Current.MainWindow;
- if (window is WindowX)
+ Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
+ var window = Application.Current.MainWindow;
+ if (window is WindowX)
+ {
- Instance.Info(window, message, icon, position, offset, durationMs, targetWindow);
- }
- else
- {
- MessageBox.Show(message, LangUtil.Get("App.Info"));
- }
+ Instance.Info(window, message, icon, position, offset, durationMs, targetWindow);
+ }
+ else
+ {
+ MessageBox.Show(message, LangUtil.Get("App.Info"));
+ }
+ }));
}
--
Gitblit v1.9.1