Results 1 to 7 of 7

Thread: Backgroundworker percentage not working

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Question Backgroundworker percentage not working

    Hey everyone! Whats the problem with this code? My progressbar isnt changed during the worker async, it only messages me on the final, and downloads the file. Thanks!
    Code:
    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
            My.Computer.Network.DownloadFile("http://fusioncountry.tk/OMSZ.rar", "E:\Rockstar Games\GTA San Andreas\SAMP\omsz.rar")
        End Sub
    
        Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
            ProgressBar1.Value = e.ProgressPercentage
    
        End Sub
    
        Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
            MessageBox.Show("Kész!")
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Backgroundworker percentage not working

    Of course it isn't changing. It's not going to happen on its own. You have to call ReportProgress if you expect the ProgressChanged event to be raised. Of course, how are you going to do that when there's no progress you can actually measure? Start by following the CodeBank link in my signature below and reading my thread about Using The BackgroundWorker. Then, realise that you can't report progress that you can't measure ands there's nothing to measure when you call that DownloadFile method. Next, get rid of all that code and look into using the WebClient class, which has built-in functionality to download asynchronously and report progress. Either that or use the overload of the DownloadFile method you're already calling that displays its own progress UI.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Backgroundworker percentage not working

    The DoWork event does not automatically raise the ProgressChanged event, because it cannot tell automatically what percentage of the work has been done so far... so you need to do it yourself.

    In this case however you are just running one command, so there isn't a way to work out the percentage done so far (just 0% before it runs, and 100% after).

    In order to get a progressbar to work with downloading a file, you will need to use a downloading method that reports progress.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Re: Backgroundworker percentage not working

    Oh okay, I understand you, but can somebody link me webclient class usage please? I didnt used it before.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Backgroundworker percentage not working

    Quote Originally Posted by Daveeed View Post
    can somebody link me webclient class usage please?
    Wow, it's quite a coincidence that neither Google nor the Help menu in VS are working for you at the same time. That's a tough break. Seriously though, you don't need us to provide a link to something you can find in seconds for yourself by simply using the documentation built into VS or a search engine. You may think we have unlimited time but it sure would help if you did your own web searches.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Backgroundworker percentage not working

    Ahhh... you can find it yourself just as easily... goto to google .... and type in vb.net webclient class and press enter. That's how you find anything new when you come across it. It's how I do it. It's probably how most of us do it. I don't think any of us just have these links ready to go... MS is always moving things around and re-arranging where stuff is, so it's easier to look it up on google (or bing, or yahoo, or if you're feeling really goosey loosey DuckDuckGo).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2018
    Posts
    61

    Re: Backgroundworker percentage not working

    Thank you guys! I resolved it, thanks for help!

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