1

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.

Here is the function :

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

End Sub

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)

Thanks.

Brian Gideon
  • 47,849
  • 13
  • 107
  • 150
David Brunelle
  • 6,528
  • 11
  • 64
  • 104

2 Answers2

3

You cannot modify objects in the UI thread directly from another thread - check out the BeginInvoke method, which lets you access UI objects across threads.

Check out WPF C# - Editing a listbox from another thread

Community
  • 1
  • 1
Nick B
  • 1,101
  • 9
  • 19
1
Private Sub FileChangeNotify()
  LstMoulures.Dispatcher.BeginInvoke (New Action(AddressOf LstMoulures.Items.Refresh))
End Sub
agent-j
  • 27,335
  • 5
  • 52
  • 79