Click here to Skip to main content
15,665,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a code so that my start button will be disabled until a certain file will be created in the background. I have asked here already and started doing this with a backgroundworker. I disabled my button in design view, and now i want the backgroundworker to keep checking if file exists and at the end to enable the startbutton. So far, i wasnt able to get the button to be enabled again. Also, if there is a faster way with something like file system watcher i could use it but i couldnt find any example on how.

What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Startbutton.Enabled = False
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Do until System.IO.File.Exists("ABC")
End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _ Handles BackgroundWorker1.RunWorkerCompleted
End Sub
Updated 28-Mar-20 3:06am
Richard MacCutchan 28-Mar-20 4:53am    
There is little point in having a background worker if the foreground does nothing while it is waiting.
Marc Kane 28-Mar-20 6:45am    
The foreground is creating this file, but it takes some time to do it (checking excel, making config in solidworks, and then saving it to new file), I just didnt copy the code in here.Now I want background to enable the button when this file is created.
Richard MacCutchan 28-Mar-20 6:51am    
Sorry, I am confused. If the foreground is creating the file, then the foreground knows when the file is created. So it also knows when to enable the button.
Marc Kane 28-Mar-20 7:07am    
Sorry, the foreground starts another app that is doing this above mentioned, so i didnt find a better way to let foreground know when the process is finished than to check if the final file has been created.
Richard MacCutchan 28-Mar-20 7:11am    
The Process class provides various methods that allow you to synchronise with an external process.

1 solution

You may consider using a FileSystemWatcher[^] instead.
Watching Folder Activity in VB.NET[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900