none
FileSystemWatcher crashes my program RRS feed

  • Question

  • Program overview --

    I have a datagridview that is populated via reading a CSV text file on form load.  I have the FileSystemWatcher set to update the datagridview if/when the text file is changed.  When the file is changed, for some reason my program completely closes and there is no error message at all.

    Following are some of my coding snippets --

       

        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            watchfolder = New System.IO.FileSystemWatcher
            watchfolder.Path = "C:\jobs\"
            watchfolder.Filter = "*.ini"
            watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
            watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
            watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes
            AddHandler watchfolder.Changed, AddressOf logchange
            watchfolder.EnableRaisingEvents = True
    
            Dim caselist() As String = System.IO.File.ReadAllLines(cases)
            For Each item In caselist
                ComboBox1.Items.Add(item)
            Next
        End Sub
    
    
        Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
            watchfolder.EnableRaisingEvents = False
            MsgBox(IO.Path.GetFileNameWithoutExtension(e.FullPath))
            updatenow()
        End Sub
    
    
      Public Sub updatenow()
            Dim table1 As DataTable = New DataTable("Jobs")
            Dim contents() As String = System.IO.File.ReadAllLines(dpath + ComboBox1.Text + ".ini")
            Dim oddjobs() As String = System.IO.File.ReadAllLines(dpath + ComboBox1.Text + ".oj")
            Dim arow(contents.Length) As DataRow
            Dim rvol As DataColumn = New DataColumn("Volume")
            Dim rbeg As DataColumn = New DataColumn("Beg Bates")
            Dim rend As DataColumn = New DataColumn("End Bates")
            Dim rpage As DataColumn = New DataColumn("Pages")
            Dim rdoc As DataColumn = New DataColumn("Documents")
            Dim rdate As DataColumn = New DataColumn("Date")
            Dim rbill As DataColumn = New DataColumn("Billed")
            Dim rnote As DataColumn = New DataColumn("Notes")
            rvol.DataType = System.Type.GetType("System.String")
            rbeg.DataType = System.Type.GetType("System.String")
            rend.DataType = System.Type.GetType("System.String")
            rpage.DataType = System.Type.GetType("System.String")
            rdoc.DataType = System.Type.GetType("System.String")
            rdate.DataType = System.Type.GetType("System.String")
            rbill.DataType = System.Type.GetType("System.Boolean")
            rnote.DataType = System.Type.GetType("System.String")
            table1.Columns.Add(rvol)
            table1.Columns.Add(rbeg)
            table1.Columns.Add(rend)
            table1.Columns.Add(rpage)
            table1.Columns.Add(rdoc)
            table1.Columns.Add(rdate)
            table1.Columns.Add(rbill)
            table1.Columns.Add(rnote)
            For x = 0 To contents.Length - 1 Step 1
                arow(x) = table1.NewRow
                Dim item As String = contents(x)
                Dim items() As String = item.Split(delimiter)
                If items(6) = "" Then
                    items(6) = False
                End If
                arow(x).ItemArray = items
                table1.Rows.Add(arow(x))
            Next
            Dim tbox(oddjobs.Length) As TextBox
            Dim ttime(oddjobs.Length) As Label
            Dim tmin(oddjobs.Length) As Label
            Dim tlist(oddjobs.Length) As CheckedListBox
            CheckedListBox1.Items.Clear()
            For x = 0 To oddjobs.Length - 1 Step 1
                Dim item As String = oddjobs(x)
                Dim items() As String = item.Split(delimiter)
                CheckedListBox1.Items.Add(items(0))
                If items(1) = "TRUE" Then
                    CheckedListBox1.SetItemChecked(x, True)
                End If
    
            Next
            DataGridView1.DataSource = table1
        End Sub

    Please help assist me in resolving this issue.

    Best,

    Garrett

    Thursday, April 26, 2012 10:50 PM

Answers

All replies