Get Process Percentage
-
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
-
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
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 ...
-
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 ...
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?
-
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 ...
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 SubPrivate 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 SubPrivate Sub My_Process()
---- Code
End Sub -
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?
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 -
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
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
-
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
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: