Reece Tilley Reece Tilley - 1 month ago 4x Question

Delaying in

my issue is i need to wait 3-4 seconds after a button has been pressed before i can check for it, here is my code under button1_click:

While Not File.Exists(LastCap)
End While


I think i'm doing something really simple wrong, i'm not the best at VB as i'm just learning so any explaining would be great!



If the reason you are needing to wait is for the file to be created try using a FileSystemWatcher and respond to the Created and Changed Events that way you are responding to an event rather than arbitrarily waiting a select period of time.

Something like:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    FileSystemWatcher1.Path = 'Your Path Here
    FileSystemWatcher1.EnableRaisingEvents = True
   'Do what you need to todo to initiate the file creation
End Sub

Private Sub FileSystemWatcher1_Created(sender As Object, e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created, FileSystemWatcher1.Changed
    If e.Name = LastCap Then
        If (System.IO.File.Exists(e.FullPath)) Then
            FileSystemWatcher1.EnableRaisingEvents = False
        End If
    End If
End Sub