Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Get Process Percentage

Get Process Percentage

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
7 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EngrImad
    wrote on last edited by
    #1

    Hello How we can get the Percentage of any Process? for example we have the the following: Private Sub My_Process() ----Code ----Code End Sub this My_Process will have a lot of codes and process and may will take a time to finish Is there a way to measure the achievement percent of M_Process while process? thanks regards

    P Richard DeemingR D 3 Replies Last reply
    0
    • E EngrImad

      Hello How we can get the Percentage of any Process? for example we have the the following: Private Sub My_Process() ----Code ----Code End Sub this My_Process will have a lot of codes and process and may will take a time to finish Is there a way to measure the achievement percent of M_Process while process? thanks regards

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      That's only possible if you have some metric for how many items the process has to work on. Such as records in a database or file. But you could also add logging such as Part 1 Beginning Part 1 Success Part 2 Beginning Part 2 Success ...

      E 2 Replies Last reply
      0
      • P PIEBALDconsult

        That's only possible if you have some metric for how many items the process has to work on. Such as records in a database or file. But you could also add logging such as Part 1 Beginning Part 1 Success Part 2 Beginning Part 2 Success ...

        E Offline
        E Offline
        EngrImad
        wrote on last edited by
        #3

        Thanks sir for reply other option could we do the following: Private Sub My_Process() Timer1.Start ----Code ----Code Timer1.Stop End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 'What we should do here to link progress bar to timer in Parallel ??? End Sub mean we shall measure the time for whole process then we need to link that time to ProgressBar to show where we are in process but here also must link the ProgressBar to timer in Parallel May be we can use threading start ProgressBar and TimerTick?? Does that Possible? If so, can show main function or code to achieve that?

        D 1 Reply Last reply
        0
        • P PIEBALDconsult

          That's only possible if you have some metric for how many items the process has to work on. Such as records in a database or file. But you could also add logging such as Part 1 Beginning Part 1 Success Part 2 Beginning Part 2 Success ...

          E Offline
          E Offline
          EngrImad
          wrote on last edited by
          #4

          Another Option here we could use "BackgroundWorker" as following:

          Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          ProgressBar1.Maximum = ???? Here what should put?
          BackgroundWorker1.WorkerReportsProgress = True
          BackgroundWorker1.RunWorkerAsync()
          End Sub

            Private Sub BackgroundWorker1\_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
             
             'We can measure this loop for example
             For t = 0 To myMax
                  Label1.Text = t
                  BackgroundWorker1.ReportProgress(t)
                  Threading.Thread.Sleep(100)
              Next
          
            'But we need to measure process percentage of (My\_Process()) , 
            'No have (t) digital counter to use in (BackgroundWorker1.ReportProgress(t))
            'So what is the solution here???
          
          
          End Sub
          

          Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
          Label1.Text = e.ProgressPercentage.ToString() & " %"
          ProgressBar1.Value = e.ProgressPercentage
          ProgressBar1.Refresh()
          End Sub

          Private Sub My_Process()
          ---- Code
          End Sub

          1 Reply Last reply
          0
          • E EngrImad

            Thanks sir for reply other option could we do the following: Private Sub My_Process() Timer1.Start ----Code ----Code Timer1.Stop End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 'What we should do here to link progress bar to timer in Parallel ??? End Sub mean we shall measure the time for whole process then we need to link that time to ProgressBar to show where we are in process but here also must link the ProgressBar to timer in Parallel May be we can use threading start ProgressBar and TimerTick?? Does that Possible? If so, can show main function or code to achieve that?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Are you saying that you're trying to estimate the amount of time the entire process will take?? That also requires that you know how many items you're going to be processing.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            1 Reply Last reply
            0
            • E EngrImad

              Hello How we can get the Percentage of any Process? for example we have the the following: Private Sub My_Process() ----Code ----Code End Sub this My_Process will have a lot of codes and process and may will take a time to finish Is there a way to measure the achievement percent of M_Process while process? thanks regards

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Have your method accept an IProgress<T> Interface (System) | Microsoft Docs[^] implementation, and call it to report the progress. The caller will need to pass in an appropriate implementation - eg: Progress<T> Class (System) | Microsoft Docs[^]. But as already mentioned, you will need to know how much work your method needs to do if you want to report how far through the work it has got.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              1 Reply Last reply
              0
              • E EngrImad

                Hello How we can get the Percentage of any Process? for example we have the the following: Private Sub My_Process() ----Code ----Code End Sub this My_Process will have a lot of codes and process and may will take a time to finish Is there a way to measure the achievement percent of M_Process while process? thanks regards

                D Offline
                D Offline
                David Mujica
                wrote on last edited by
                #7

                How about this approach ... 1) Run the process as a test, collecting the total time it takes. Call it "T" 2) Store that run time somewhere 3) Next time you run the process you can now use "T" as the denominator to calculate the percent complete. p = duration_now/T 4) If the percentage calculation goes over 100, then set it 100. 5) Capture the new total time, "T", store it for the next iteration. Rinse, repeat. Not perfect, but it might work for you. :java:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups