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.
kevin1265Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bchoorCommented:
I'm not sure if you copied-pasted directly from your code. You dimension 'myFrom' but are setting on 'myForm'
         
Dim myFrom as new Form2
            ^^

myForm.Show()
      ^^



You may try also - myForm.ShowDialog() - so then it'll be modal - like a message box.

HTH
~BC

ericwong27Commented:
Try this

I using CLR2.0 new feature (No multi form pop up)

Form2.Text = "Create"
Form2.Show()

Instead of

Dim myform as new form2
myform.Text = "Create"
myform.Show()



Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        With Me.FileSystemWatcher1
            .EnableRaisingEvents = True
            .Path = "C:\Temp"
            .Filter = "*.*"
        End With

    End Sub

    Private Sub FileSystemWatcher1_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) _
    Handles FileSystemWatcher1.Changed, FileSystemWatcher1.Created, FileSystemWatcher1.Deleted

        Select Case e.ChangeType
            Case IO.WatcherChangeTypes.Created
                Form2.Text = "Create"
                Form2.Show()
            Case IO.WatcherChangeTypes.Deleted
                Form2.Text = "Delete"
                Form2.Show()
            Case IO.WatcherChangeTypes.Renamed
                Form2.Text = "Rename"
                Form2.Show()
        End Select

    End Sub


End Class

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kevin1265Author Commented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.