技术栈

WPF程序中 Invoke的使用

西飘客2024-06-29 16:07

WinForms

private delegate void UpdateUiTextDelegate(Control control, string text);
private void UpdateUiText(Control control, string text)
{
if(InvokeRequired)
{
Invoke(new UpdateUiTextDelegate(UpdateUiText), new object[] {control, text});
return;
}
control.Text = text;
}

WPF

private void UpdateUiText(Control control, string text)
{
if(!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(DispatcherPriority.Send, new UpdateUiTextDelegate(UpdateUiText), control, text);
return;
}
control.Text = text;
}

上一篇:FFmpeg has three concatenation methods
下一篇:如何理解泛型的编译期检查
相关推荐
超级种码
8 分钟前
Redis:Redis高可用——副本、哨兵和集群
数据库·redis·wpf
棉晗榜
11 分钟前
wpf给Border添加闪烁边框
wpf
Derrick_itRose
14 分钟前
DevExpress笔记WPF(2)Data Editors and Controls(基础编辑器)
笔记·编辑器·wpf
曹天骄
16 小时前
Cloudflare KV 使用教程(基于 Wrangler 项目)
wpf
摘星编程
21 小时前
Flutter for OpenHarmony 实战:Dialog 对话框详解
flutter·wpf
ou.cs
1 天前
WPF TreeView 自动展开所有节点:附加行为(Attached Behavior)保姆级实现教程
c#·.net·wpf
一念春风
1 天前
可视化视频编辑(WPF C#)
开发语言·c#·wpf
bugcome_com
3 天前
C# 字符串拼接全面指南
c#·.net·wpf
bugcome_com
4 天前
WPF样式进阶实战:外置样式+MVVM主题切换+样式优先级全解析
c#·.net·wpf
热门推荐
01GitHub 镜像站点02网站改了域名,如何查找?03Linux下V2Ray安装配置指南04Labelme从安装到标注:零基础完整指南05安娜的档案(Anna’s Archive) 镜像网站/国内最新可访问入口(持续更新)06自用Proteus(8.15)常用元器件图示和功能介绍(持续更新...)07AI 规范驱动开发“三剑客”深度对比:Spec-Kit、Kiro 与 OpenSpec 实战指南082025-04-03 Latex学习1——本地配置Latex + VScode环境09百度网盘偷偷给电脑“降频”?10【踩坑笔记】50系显卡适配的 PyTorch 安装