【问题标题】:WPF : Accessing a UI object with a Thread gives an errorWPF:使用线程访问 UI 对象会出错
【发布时间】:2011-07-06 00:19:08
【问题描述】:

我有一个在文件夹中修改文件时调用的函数。此函数更新存储在 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。” (翻译:调用线程无法访问这个对象,因为它被另一个线程拥有)

谢谢。

【问题讨论】:

    标签: .net wpf vb.net multithreading


    【解决方案1】:

    您不能直接从另一个线程修改 UI 线程中的对象 - 请查看 BeginInvoke 方法,该方法允许您跨线程访问 UI 对象。

    查看WPF C# - Editing a listbox from another thread

    【讨论】:

      【解决方案2】:
      Private Sub FileChangeNotify()
        LstMoulures.Dispatcher.BeginInvoke (New Action(AddressOf LstMoulures.Items.Refresh))
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-17
        • 1970-01-01
        • 2021-05-12
        • 1970-01-01
        • 2018-04-27
        相关资源
        最近更新 更多