-
Jan 6th, 2019, 06:45 AM
#1
Thread Starter
Member
[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
Last edited by Daveeed; Jan 6th, 2019 at 05:36 PM.
-
Jan 6th, 2019, 07:10 AM
#2
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.
-
Jan 6th, 2019, 07:28 AM
#3
Thread Starter
Member
Re: Delay in a function(?)
Okay, but how I return that value instead of the check function?
-
Jan 6th, 2019, 08:05 AM
#4
Re: Delay in a function(?)
Where are you calling that 'check' method and what are you doing with the result?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|