跨线程调用UI控件时会出现无法访问对象的错误
用委托实现跨线程调用
调试结果:
Solution Explore:
MainWindow.xaml
<Window x:Class="委托刷新UI线程.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:委托刷新UI线程"
mc:Ignorable="d"
Title="MainWindow" Height="100" Width="100" WindowStyle="ToolWindow">
<Grid Background="Gray">
<TextBox Name="textBox

本文介绍了在WPF中遇到跨线程访问UI控件时抛出'System.InvalidOperationException'异常的问题,并详细说明如何通过使用委托来正确刷新UI线程,确保线程安全。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



