Reputation: 6440
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.
Upvotes: 1
Views: 4719
Reputation: 27913
Private Sub FileChangeNotify()
LstMoulures.Dispatcher.BeginInvoke (New Action(AddressOf LstMoulures.Items.Refresh))
End Sub
Upvotes: 1
Reputation: 1101
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
Upvotes: 3