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
  • 46,608
  • 12
  • 102
  • 146
David Brunelle
  • 6,388
  • 11
  • 59
  • 102

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,093
  • 9
  • 19
1
Private Sub FileChangeNotify()
  LstMoulures.Dispatcher.BeginInvoke (New Action(AddressOf LstMoulures.Items.Refresh))
End Sub
agent-j
  • 26,389
  • 5
  • 49
  • 78