Link to home
Start Free TrialLog in
Avatar of kevin1265
kevin1265

asked on

FileSystemWatcher show form on file create

Hey Experts,

I have been smashing my head into a wall the last week trying to figure this out. I am sure it will turn out being something simple.

First off, I am using VB.NET from VS 2005.

I am monitoring a directory for a specific file type, lets say they are txt files.
On creation I want to create an instance of form2.
set vars on it, then show it.

so I have the following which fires  when the watcher detects a change
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub logchange(ByVal source As Object, ByVal e As _
                      System.IO.FileSystemEventArgs)
        If e.ChangeType = IO.WatcherChangeTypes.Changed Then

            '  MsgBox("File " & e.FullPath & _
            '                        " has been modified" & vbCrLf)
        End If
        If e.ChangeType = IO.WatcherChangeTypes.Created Then

            ' MsgBox("File " & e.FullPath & _
            '                        " has been created" & vbCrLf)
           
            Dim myFrom as new Form2
            myForm.label1.text="SOME VALUE"
            myForm.Show()


        End If
        If e.ChangeType = IO.WatcherChangeTypes.Deleted Then

            'MsgBox("File " & e.FullPath & _
            '                         " has been deleted" & vbCrLf)
        End If
    End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

This works great when I just use message boxes but when attempt to display the form, it appears then kinda locks in place creating a white backround.

I understand that the watcher is running on another thread, and understand the concept of invoke and delegates but I simply can not figure this out.
SOLUTION
Avatar of bchoor
bchoor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of ericwong27
ericwong27
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kevin1265
kevin1265

ASKER

Eric you the man, you have no idea how much this helped.

Bchoor thanks this works as well however it freezes my GUI.

Thanks for the quick response.