Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15189

how do i disable FileSystemWatcher after file is found?

$
0
0
hello
is there a way to disable FileSystemWatcher after file is found?
beacuse it continues to loop.
this my code.
Code:


'in form load =====================================
        Dim watched As String = Path.Combine("C:\ESystem\EOUT")
        Dim fsw As New FileSystemWatcher(watched)
        fsw.NotifyFilter = NotifyFilters.FileName Or NotifyFilters.LastWrite Or NotifyFilters.CreationTime
        fsw.EnableRaisingEvents = True
        fsw.Filter = "*.out"
        AddHandler fsw.Created, AddressOf Fsw_Changed

Code:

    Private Sub Fsw_Changed(ByVal sender As Object, ByVal e As FileSystemEventArgs)

        Try

            Call Readfile()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "err", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub


Code:

  Private Sub Readfile()
        Dim line As String = String.Empty

        Try

            Using objReader As New StreamReader("C:\ESystem\EOUT\ECharge.out")
                line = objReader.ReadLine
                If Mid(line, 1, 3) = "000" Then
                    Dim EResultRecord As String = line
                    DialogResult = DialogResult.OK
                Else
                    EResultRecord = 300
                End If
            End Using
         
        Catch ex As Exception
            MessageBox.Show(ex.Message, "err", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

thanx for any help
salsa :)

Viewing all articles
Browse latest Browse all 15189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>