mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-03 23:06:34 +08:00
暂停更新 Workbench(WPF)项目
This commit is contained in:
@@ -15,7 +15,8 @@ namespace Serein.Library.Utils
|
||||
/// </summary>
|
||||
public class UIContextOperation
|
||||
{
|
||||
private readonly SynchronizationContext context;
|
||||
private SynchronizationContext context;
|
||||
private readonly Func<SynchronizationContext> getUiContext = null;
|
||||
|
||||
static UIContextOperation()
|
||||
{
|
||||
@@ -42,12 +43,25 @@ namespace Serein.Library.Utils
|
||||
this.context = synchronizationContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 传入UI线程上下文
|
||||
/// </summary>
|
||||
/// <param name="synchronizationContext">线程上下文</param>
|
||||
public UIContextOperation(Func<SynchronizationContext> getUiContext)
|
||||
{
|
||||
this.getUiContext = getUiContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步方式进行调用方法
|
||||
/// </summary>
|
||||
/// <param name="uiAction">要执行的UI操作</param>
|
||||
public void Invoke(Action uiAction)
|
||||
{
|
||||
if(context is null && getUiContext != null)
|
||||
{
|
||||
context = getUiContext.Invoke();
|
||||
}
|
||||
context?.Post(state =>
|
||||
{
|
||||
uiAction?.Invoke();
|
||||
@@ -61,6 +75,10 @@ namespace Serein.Library.Utils
|
||||
/// <returns></returns>
|
||||
public Task InvokeAsync(Action uiAction)
|
||||
{
|
||||
if (context is null && getUiContext != null)
|
||||
{
|
||||
context = getUiContext.Invoke();
|
||||
}
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
context?.Post(state =>
|
||||
|
||||
Reference in New Issue
Block a user