WPF\MAUI\Avalonia Dispatcher

Dispatcher为线程的调度器,最常见是Application.Current.Dispatcher.Invoke(...)在UI线程上执行一些内容,在某些场景下可将Dispatcher放入Action、或者通过Action将参数传递给UI线程的Dispatcher,以实现在其他线程上(如定时器)中调用UI线程执行一些内容;

  1. WPF
  • Application.Current.Dispatcher: UI线程的Dispatcher;

  • Dispatcher.CurrentDispatcher:当前线程的Dispatcher,线程没有Dispatcher就自动关联一个;

  • FrameworkElement.Dispatcher:该控件所属线程的Dispatcher;

  1. MAUI
  • Application.Current.Dispatcher: UI线程的Dispatcher;

  • Microsoft.Maui.Dispatching.Dispachter.GetForCurrentThread():当前线程的Dispatcher,没有更换则返回null;

  • Element.Dispatcher:该控件所属线程的Dispatcher;

  • IPlatformApplication.Current.Services.GetRequiredService<IDispathcer>():从DI容器中直接拿Dispathcer,IPlatformApplication是MAUI自带的DI容器访问接口,WPF和Avalonia都没有,IPlatformApplication.Current.Services就是MauiApp.CreartBuilder().Service;

  1. Avalonia
  • Avalonia.Threading.Dispatcher.UIThread.Invoke(...):UI线程上直接执行;

  • Visual.Dispatcher:该控件所属线程的Dispatcher,就是UIThread的Dispathcer,与WPF、MAUI不同;

相关推荐
dalong108 小时前
WPF:箭头绘制程序
wpf·自定义绘制
张工在路上1 天前
WPF 布局基础概述
大数据·hadoop·wpf
迪飞特科技2 天前
分布式事务下 Spring 声明式事务失效的 3 种修复方案
分布式·spring·wpf
2601_962174175 天前
Redis 简介
数据库·redis·wpf
SamChan906 天前
Python+PyMuPDF提取PDF表格并翻译:表格结构检测与双语重建实战
windows·python·ai·pdf·wpf
SamChan906 天前
Python+OpenCV检测PDF翻译后排版偏移:像素级格式一致性验证
python·opencv·ai·pdf·wpf
FuckPatience6 天前
WPF 拿到控件的最初样式,修改获得焦点样式
wpf
主宰者6 天前
【WPF】MainWindow前添加加载窗口,发现加载过程中有白色无内容窗口闪烁一下的解决方案
wpf
Vae_Mars7 天前
WPF中的ControlTemplate(控件模板)
wpf
SamChan907 天前
Python+ReportLab自动生成PDF翻译质量审计报告:从数据到可视化的完整方案
开发语言·python·ai·pdf·wpf