[RESOLVED] Delay in a function(?)
Hey! I have a function, which checks two file sizes, one from an URI and one from my computer if they are the same or not, but the problem is, that the URI file is needed to be start downloading, and it takes some miliseconds while it gives me the value, but its too late, because my conditions are running, and it gives me only the 0. How can i set a delay between the download starting, and the condition? Thank you, and sorry for my bad english!
Code:
Function check() As Integer
Dim a As Integer
wca = New System.Net.WebClient
Dim uri As New Uri("http://fusioncountry.tk/custom.img")
wca.DownloadFileAsync(uri, My.Computer.FileSystem.SpecialDirectories.Temp & "\temp1download.tmp")
If (My.Computer.FileSystem.FileExists(hely & "\SAMP\SAMP.col") Or My.Computer.FileSystem.FileExists(hely & "\SAMP\SAMP.def")) And My.Computer.FileSystem.FileExists(hely & "\SAMP\custom.img") Then
If Int(My.Computer.FileSystem.GetFileInfo(hely & "\SAMP\custom.img").Length) = meret Then
a = 0
Else
a = 2
End If
Return a
ElseIf My.Computer.FileSystem.FileExists(hely & "\SAMP\custom.img") Then
If Int(My.Computer.FileSystem.GetFileInfo(hely & "\SAMP\custom.img").Length) <> meret And My.Computer.FileSystem.FileExists(hely & "\SAMP\SAMP.col") = False And My.Computer.FileSystem.FileExists(hely & "\SAMP\SAMP.def") = False Then
a = 1
Else
a = 2
End If
Return a
Else
a = 2
End If
Return a
End Function
Private Sub wca_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles wca.DownloadProgressChanged
meret = e.TotalBytesToReceive
Int(meret)
wca.CancelAsync()
End Sub
Re: Delay in a function(?)
Um, maybe you should put your comparison in the ProgressChanged event handler, given that that is where you know the size of the remote file. You don't need a delay. You just need to structure your code sensibly.
Re: Delay in a function(?)
Okay, but how I return that value instead of the check function?
Re: Delay in a function(?)
Where are you calling that 'check' method and what are you doing with the result?