From 589c0490bfec129eb59761103dc06ee84d276a1f Mon Sep 17 00:00:00 2001 From: fengjiayi <12821976+ning_xi@user.noreply.gitee.com> Date: Thu, 12 Dec 2024 20:53:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86UIContextOperation?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Utils/UIContextOperation.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Library/Utils/UIContextOperation.cs b/Library/Utils/UIContextOperation.cs index f2a7700..74f7c9a 100644 --- a/Library/Utils/UIContextOperation.cs +++ b/Library/Utils/UIContextOperation.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -8,12 +9,30 @@ using System.Threading.Tasks; namespace Serein.Library.Utils { /// - /// 为类库提供了在UI线程上下文操作的方法,如果你在Windows平台上运行,不必手动实例化该类 + /// 为类库提供了在UI线程上下文操作的方法(使用Serein.Workbench时不用处理) + /// 在WPF、Winform项目中,多线程中直接操作UI线程可能发生非预期的异常 + /// 所以当你设置自己的平台时,需要手动实例化这个工具类 /// public class UIContextOperation { private readonly SynchronizationContext context; + static UIContextOperation() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + + } + } + /// /// 传入UI线程上下文 ///