Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Try to get one loop to finish before starting another in Visual Studio 2010

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
131
PHP:
Private Sub btnReload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReload.Click
        Dim patchReader() As String = File.ReadAllLines(Application.StartupPath & "\Updatelist.tmp")
        For Each d In patchReader
            Dim str = d
            str = str.Substring(0, str.LastIndexOf(".zip", StringComparison.OrdinalIgnoreCase))
            File.Delete(str)
            Dim str2 = d
            download = New WebClient
            download.DownloadFileAsync(New Uri("http://localhost/" & str2), str2)
            System.Threading.Thread.Sleep(3000)
            
        Next

NEED IT TO FINISH ^^ LOOP TO DOWNLOAD ALL FILES BEFORE STARTING THIS NEXT ONE

PHP:
        'Delete the zip files when done!
        For Each t In patchReader
            Dim str1 = t
            Dim sc As New Shell32.Shell()
            'Create directory in which you will unzip your files .
            Dim output As Shell32.Folder = sc.NameSpace(Application.StartupPath)
            'Declare your input zip file as folder  .
            Dim input As Shell32.Folder = sc.NameSpace(Application.StartupPath & "\" & str1)
            'Extract the files from the zip file using the CopyHere command .
            output.CopyHere(input.Items, 4)
        Next

        For Each d In patchReader
            Dim fin = d
            File.Delete(fin)
        Next
    End Sub

Any ideas would be greatful. Thanks guys.
 
◝(⁰▿⁰)◜Smile◝ (⁰▿⁰)◜
Developer
Joined
May 29, 2007
Messages
2,167
Reaction score
899
  • Run the first code inside a background worker
  • Add the second code to the on complete method.

is some information on how to use a backgroundworker.

If you're going to use a backgroundworker, then remove don't use DownloadFileAsync function but use DownloadFile instead. This will only allow you to download one file at the time tough but it will make the thread wait until all downloads are completed.



This is dangerously close to breaking section rule #5 . Please read the stickied section rules thread and edit your post with more information about your problem or/and what you've already tried to fix it. Thanks.
Don't worry, anyone with a enough knowledge of the .NET framework know that there is a backgroundworker and knows how to solve this easy problem.
 
Junior Spellweaver
Joined
Oct 27, 2008
Messages
165
Reaction score
89
You're using asynchronous to download files, which will create threads for each download, if you're looking at MSDN metods remarks, it says how the files are downloaded.

The link above said:
This method downloads the resource at the URI specified by in the address parameter. When the download completes successfully, the downloaded file is named fileName on the local computer. The file is downloaded asynchronously using thread resources that are automatically allocated from the thread pool. To receive notification when the file is available, add an event handler to the DownloadFileCompleted event.




Also youre code has memory, leaks, don't create new objects for every download you make.

If you want to download multiple files look into this:

And use this method:
 
Last edited:
Back
Top