invoke to marshal
-
i was told i need to use invoke to marshal to fix this exception : Control 'TxtFolderActivity' accessed from a thread other than the thread it was created on. i cant seem to figure it out. here is the snippet of code where i need the invoke.
Private Sub logchange(ByVal source As Object, ByVal e As _ System.IO.FileSystemEventArgs) If e.ChangeType = IO.WatcherChangeTypes.Changed Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been modified" & vbCrLf End If If e.ChangeType = IO.WatcherChangeTypes.Created Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been created" & vbCrLf End If If e.ChangeType = IO.WatcherChangeTypes.Deleted Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been deleted" & vbCrLf End If End Sub
Makniteasy -
i was told i need to use invoke to marshal to fix this exception : Control 'TxtFolderActivity' accessed from a thread other than the thread it was created on. i cant seem to figure it out. here is the snippet of code where i need the invoke.
Private Sub logchange(ByVal source As Object, ByVal e As _ System.IO.FileSystemEventArgs) If e.ChangeType = IO.WatcherChangeTypes.Changed Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been modified" & vbCrLf End If If e.ChangeType = IO.WatcherChangeTypes.Created Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been created" & vbCrLf End If If e.ChangeType = IO.WatcherChangeTypes.Deleted Then TxtFolderActivity.Text &= "File " & e.FullPath & _ " has been deleted" & vbCrLf End If End Sub
MakniteasyYou're not allowed to interact with a Form on a separate thread. What you need to do is call BeginInvoke(). What this will do is push a delegate to the end of the Windows message queue. That delegate will be invoked on the UI thread, which will allow you to safely write your string to the TextBox. The following article has more information. See the code example at the bottom. http://www.codeproject.com/csharp/begininvoke.asp[^]