Add WinUIDispatcher
This commit is contained in:
@@ -1,9 +1,4 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Toolkit.Foundation;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
namespace Toolkit.WinUI;
|
namespace Toolkit.WinUI;
|
||||||
@@ -12,7 +7,15 @@ public static class IServiceCollectionExtensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddWinUI(this IServiceCollection services)
|
public static IServiceCollection AddWinUI(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddTransient<IDispatcher, WinUIDispatcher>();
|
||||||
services.AddTransient<IDispatcherTimerFactory, DispatcherTimerFactory>();
|
services.AddTransient<IDispatcherTimerFactory, DispatcherTimerFactory>();
|
||||||
|
|
||||||
|
services.AddTransient((Func<IServiceProvider, IProxyServiceCollection<IComponentBuilder>>)(provider =>
|
||||||
|
new ProxyServiceCollection<IComponentBuilder>(services =>
|
||||||
|
{
|
||||||
|
|
||||||
|
})));
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.UI.Dispatching;
|
||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Toolkit.WinUI;
|
||||||
|
|
||||||
|
public class WinUIDispatcher :
|
||||||
|
IDispatcher
|
||||||
|
{
|
||||||
|
public Task Invoke(Action action)
|
||||||
|
{
|
||||||
|
DispatcherQueue.GetForCurrentThread().TryEnqueue(action.Invoke);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user