Question FileSystemWatcher and Loading MDI Children doesn't work

hshot_rooke

New member
Joined
Sep 4, 2008
Messages
4
Programming Experience
5-10
Hello fellow developers

Using Visual Studio 2008.

I have a question regarding the FileSystemWatcher.
I'm trying to load an MDI child inside a parent on the "created" event of my FileSystemWatcher. The code runs through fine, but the MDI child never shows inside the parent. If I have a separate button on the toolbar of my application, the MDI child shows up fine.

Is this a bug in VS2008? Seems very straightforward, but the child never shows. Debugging the application, it hits all the events fine and runs through all the code fine without exceptions, but never actually does anything.

Any help on this situation would be greatly appreciated. Thank you.

Sample code:

VB.NET:
    Private Sub MDIParent1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Initalize_Watcher()
    End Sub

    Private Sub Initalize_Watcher()
        Dim toWatch As String = String.Empty

        toWatch = "C:\PFEX Test\Interface Output"
        If Not toWatch.Equals(String.Empty) Then
            _Fsw = New System.IO.FileSystemWatcher(toWatch, "*.pfx")
            _Fsw.EnableRaisingEvents = True
        End If
    End Sub

    Private Sub _Fsw_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles _Fsw.Created
        With My.Forms.Form1
            .WindowState = FormWindowState.Maximized
            .Show()
            .Activate()
        End With
    End Sub
 
Upon closer inspection, adding a watch to the "My.Forms.Update" object, under the property "AccessibilityObject" has the value "Error creating window handle". But does NOT generate an exception for some reason.

Which sounds like it is the problem. I'm guessing the, the "created" event of the FileSystemWatcher is having problems accessing the My.Forms collection?

Man, this is a pain in the butt.
 
Last edited:
VB.NET:
    Private Sub _Fsw_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles _Fsw.Created
        Dim NewChild As New Form1
        With NewChild 
            .WindowState = FormWindowState.Maximized
            .MDIParent = Me
            .Show()
        End With
    End Sub
 
Back
Top