Results 1 to 4 of 4

Thread: [RESOLVED] Delay in a function(?)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    31

    Resolved [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.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,034

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2018
    Posts
    31

    Re: Delay in a function(?)

    Okay, but how I return that value instead of the check function?

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,034

    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
  •  



Click Here to Expand Forum to Full Width