Turn on the button when the image finishes downloading.

So, I have a problem in Visual Basic, I got this code that loads a picture.

WC.DownloadFileAsync(New Uri("picturelinkhere"), "c:\myfile.jpg") 

After that I have a code that unloads the download button

 Button1.Enabled = False 

The thing is, I want to wait for the file to finish loading before turning Button1 back on.

I tried to use

 System.Threading.Thread.Sleep(1000) 

But the problem is that it makes progress in the program very lagged.

Any ideas?

+4
source share
1 answer

According to MSDN :

To be notified when a file is available, add an event handler to the DownloadFileCompleted event.

So, for example, you can do something like this:

 AddHandler WC.DownloadFileCompleted, AddressOf DownloadFileCompleted 

And then re-enable the button in the event handler method, for example:

 Private Sub DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Button1.Enabled = True End Sub 
+3
source

Source: https://habr.com/ru/post/1479529/


All Articles