hog Posted September 8, 2003 Posted September 8, 2003 I have an app that I want to sit and wait for two files that are being created from another application. When these files are detected I want the screen to be updated and a button enabled to allow further processing of these two require files. This is what I'm attempting but with little success: Do While True Application.DoEvents() ' if file one exists update screen ' if file two exist update screen ' if both files exits enable button and jump out of loop Loop Is this something that I should be using a Thread on? Bear in mind I haven't used threads before which is why for something so simple I'm using the DoEvents method:) Quote My website
Leaders dynamic_sysop Posted September 8, 2003 Leaders Posted September 8, 2003 you could always try using the io.systemfilewatcher , eg: Dim WithEvents fw As IO.FileSystemWatcher Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click fw = New IO.FileSystemWatcher("C:\testing") With fw .EnableRaisingEvents = True .WaitForChanged(IO.WatcherChangeTypes.Created) .BeginInit() Application.DoEvents() End With End Sub Private Sub fw_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fw.Changed If e.Name = "first file created" Then '//do stuff when the file gets made. ElseIf e.Name = "second file created" Then '//do stuff for the other file. End If End Sub hope it puts you on track :) Quote
*Experts* mutant Posted September 8, 2003 *Experts* Posted September 8, 2003 Use the FileSystemWatcher component, its in your toolbox under Components section or IO.FileSystemWatcher. Set the filter to monitor a directory and use the Created event to check the file names. Quote
hog Posted September 8, 2003 Author Posted September 8, 2003 Okey dokey thanks chaps, I'll give it a whirl. I did get my code to work eventually like this.......I take it is is less efficient than the filewatcher? Do While True ' let the computer carry on with background events Application.DoEvents() ' check for files and if they exist update the screen fFile1 = New FileInfo(strFileP1) If fFile1.Exists Then Me.chkP1Detected.Checked = True End If fFile2 = New FileInfo(strFileP2) If fFile2.Exists Then Me.chkP2Detected.Checked = True End If ' if both files exist enable button to allow user to generate p3.txt interface file ' and jump out of loop If Me.chkP1Detected.Checked And Me.chkP2Detected.Checked Then Me.cmdGenerateP3.Enabled = True Exit Do End If Loop ps congratulations on the twins:):) Quote My website
*Experts* Bucky Posted September 8, 2003 *Experts* Posted September 8, 2003 The FileSystemWatcher is much more efficient and proper to use. It creates a system-wide hook that receives messages whenever file changes take place. It is only "running" when it's needed, but your method is hogging (no pun intended) all kinds of system resources. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
hog Posted September 8, 2003 Author Posted September 8, 2003 man I's jus gotta say I lus your avitar....I can't stop laughin lol:) Yep I recoded to use the filewatcher so no more hoggin :) Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.