You can use Timer control.
Set Enabled=True on Timer properties
Set Interval as you needed. Interval in milliseconds. (e.g 1000 = 1 Second)
Then put your checking code in Timer event :
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' Your Code
End Sub
Jx_Man
Senior Poster
3,553 posts since Nov 2007
Reputation Points: 1,500
Solved Threads: 531
Skill Endorsements: 65
What is ur actual need? U want to keep checking for file exist or not all the time ur application is running?
Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 60
Solved Threads: 158
Skill Endorsements: 1
You might want to check out the FileSystemWatcher control. I think it is better to let the system notify you of changes than to continuously poll the system. Wrox Press Visual Basic 2008 Programmer's Reference says:
The FileSystemWatcher class keeps an eye on part of the file system and raises events to let your program know if something changes. For example, you could make a FileSystemWatcher monitor a work directory. When a new file with a .job extension arrives, the watcher could raise an event and your application could process the file.
The FileSystemWatcher class’s constructor takes parameters that tell it which directory to watch and that give it a filter for selecting files to watch. For example, the filter might be “ *.txt ” to watch for changes to text files. The default filter is “ *.* ” , which catches changes to all files that have an extension.
Set the filter to the empty string “ ” to catch changes to all files including those without extensions.
The NotifyFilter property "Determines the types of changes that the watcher reports. This is a combination of values defined by the NotifyFilters enumeration and can include the values Attributes, CreationTime, DirectoryName, FileName, LastAccess, LastWrite, Security, and Size.
Reverend Jim
Illigitimae non carborundum
3,737 posts since Aug 2010
Reputation Points: 585
Solved Threads: 469
Skill Endorsements: 33
See if this helps.
Public Class Form1
Private myFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\" '// folder for file.
Private myFile As String = myFolder & "contact4.txt" '// file to check if .Exists.
Private WithEvents tmrFileExists As New Timer With {.Interval = 1000, .Enabled = True} '// dynamic Timer.
Private Sub tmrFileExists_Tick(sender As Object, e As System.EventArgs) Handles tmrFileExists.Tick
Button2.Enabled = IO.File.Exists(myFile) '// toggle Button2 Enabled/Disabled.
End Sub
End Class
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
Change myFolder to your folder.
Example: Private myFolder As String = "C:\Program Files\Fast_Automatic_Accident_Notification_Through_SMS\Resources\" '// folder for file. You do Not need to add a Timer, it has already been added dynamically on line.4.
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
For this typeOf(issue), use a Boolean; reason: Booleans only toggle between a True/False and Nothing Else.
Public Class Form1
Private myFolder As String = "\My Documents\"
Private myFile As String = myFolder & "123.txt" '// file to check if .Exists.
Private WithEvents tmrFileExists As New Timer With {.Interval = 1000, .Enabled = True} '// dynamic Timer.
Private bIsButtonClickable As Boolean = True '// Boolean to determine if Button is clickable.
Private Sub tmrFileExists_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrFileExists.Tick
If mySelectedCoolFileExists() = True Then
_Button1_Click(sender, New System.EventArgs())
Else
bIsButtonClickable = True
End If
End Sub
Private Sub _Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If bIsButtonClickable = True Then
If mySelectedCoolFileExists() = True Then
bIsButtonClickable = False
MessageBox.Show("file exits")
End If
End If
End Sub
Private Function mySelectedCoolFileExists() As Boolean
If System.IO.File.Exists(myFile) = True Then
Return True
Else
Return False
End If
End Function
End Class
It checks twice for the File, though if it were not morning here, I would have had it check for the file only once, by using another Boolean of course.:)
Other than that, glad I could be your wing.man for the time being and glad I could help.:)
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8
:)
(btw: that smiley isNot for reply to your post, though glad I could help; that smiley is to look down on the "Marked as Solved", for when it finally gets there. Guess I'm just one step ahead, as I seem to be.
codeorder
Postaholic
2,124 posts since Aug 2010
Reputation Points: 256
Solved Threads: 387
Skill Endorsements: 8