WPF:使用线程访问 UI 对象会出现错误 [英] WPF : Accessing a UI object with a Thread gives an error

查看:23
本文介绍了WPF:使用线程访问 UI 对象会出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在文件夹中修改文件时调用的函数.此函数更新存储在 UI 中的列表视图的项目.

I have a function that is called when a file is modified in a folder. This function updates the items of a listview which is stored in the UI.

这是函数:

Private Sub FileChangeNotify()
    Try
        LstMoulures.Items.Refresh()
    Catch ex As Exception
        MsgBox(Ex.exception)
    End Try

End Sub

这是错误:Le thread appelant ne peut pas accéder à cet objet parce qu'un autre thread en est propriétaire."(翻译:调用线程不能访问这个对象,因为它被另一个线程拥有)

Here is the error: "Le thread appelant ne peut pas accéder à cet objet parce qu'un autre thread en est propriétaire." (Translation : The calling thread cannot access this object because it is owned by another thread)

谢谢.

推荐答案

Private Sub FileChangeNotify()
  LstMoulures.Dispatcher.BeginInvoke (New Action(AddressOf LstMoulures.Items.Refresh))
End Sub

这篇关于WPF:使用线程访问 UI 对象会出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆