I am trying to make a CheckedListBox_Notifications that shows items listing the changes happening in a specific directory. Upon the load of the form I have the code:
Public Watcher_ActiveProjects As New FileSystemWatcher()
Sub Form_Home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Watcher_ActiveProjects
Watcher_ActiveProjects = New FileSystemWatcher() With {
.Path = Directory_ActiveProjects,
.IncludeSubdirectories = True,
.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.DirectoryName Or NotifyFilters.LastWrite,
.EnableRaisingEvents = True
}
AddHandler Watcher_ActiveProjects.Created, AddressOf oncreate
end sub
And so upon "OnCreate" I am adding the item using the code:
Public Sub oncreate(sender As Object, e As FileSystemEventArgs)
'Set Variables
strFullPath = e.FullPath
strProjectSuffix = Split(strFullPath, "\")(3)
Form_Home.CheckedListBox_Notifications.Items.Add("File created:")
End Sub
The problem is that using OnCreate sub it doesn't update the CheckedListBox_Notifications. I hear that it might be related to threading? Could someone, please, help me with this one?