FileSystemWatcher Changed event is raised twice

前端 未结 30 3310
死守一世寂寞
死守一世寂寞 2020-11-22 06:01

I have an application where I am looking for a text file and if there are any changes made to the file I am using the OnChanged eventhandler to handle the event

30条回答
  •  不思量自难忘°
    2020-11-22 06:11

    I approached the double create issue like this, which ignores the first event:

    Private WithEvents fsw As New System.IO.FileSystemWatcher
    Private complete As New List(Of String)
    
    Private Sub fsw_Created(ByVal sender As Object, _
        ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Created
    
        If Not complete.Contains(e.FullPath) Then
            complete.Add(e.FullPath)
    
        Else
            complete.Remove(e.FullPath)
            Dim th As New Threading.Thread(AddressOf hprocess)
            th.Start(e)
    
        End If
    
    End Sub
    

提交回复
热议问题