none
How do I improve performance of updating a Progressbar on a wpf window?

    Question

  • I have an Extension to Visual Studio 2015 to print the source code in color. In order to provide feedback to the user I have a wpf window with couple of progressbars and labels that show how the source code processing is progressing.

    Here is the progress window:

    The progressbar numbered 1 and labels numbered 2 and 3 are updated by calling a method in code-behind for the progress window. I prefer to update the progress every time the extension processes a line of source code, however, that slows down the whole process. 

    The following table shows the overall time taken to process 1500 lines of source code and update 1,2 and 3 in the screenshot:

    update Line Interval       Time taken to process 1500 lines

    1                                  46 seconds
    10                                25 seconds
    100                              18 seconds

    As you can see that updating every line is not an option. Is there a recommend way to implement feedback so that it has minimum impact on the overall process?

    I am new to WPF so might be doing something very wrong!!

    Below is the method used to update the progressbar and labels.

      Friend Sub ShowProgress( ByVal CurrentValue As Integer)
        Dispatcher.BeginInvoke(Sub() ShowProgressInBackground(CurrentValue))
        DoEvents()
      End Sub
      
      Friend Sub ShowProgressInBackground(ByVal CurrentValue As Integer)
         If CurrentValue Mod 1 = 0 Then
           lblProjectItemProgress.Content = String.Format("{0} of {1} {2}", CurrentValue, pbrProjectItem.Maximum, m_ProgressMeasurementUnits)
           
          txtTotalLinesOutput.Content = String.Format(CultureInfo.InvariantCulture, "Total {0:0,0} Lines Output", m_LinesOutput)
    
          If CurrentValue < pbrProjectItem.Maximum Then
             pbrProjectItem.Value = CurrentValue
          End If
       End If
     End Sub

    I have uploaded a test app that you can try by changing the update Interval:

    StarPrintTools.com/PreRelease/WPF_Progressbar.zip

    Timing table that shows the overall time taken when the progressbar is updated:
         Interval     Overall Loop Time
         1              23:46 seconds
         10              3:09 seconds
         100              :42 seconds
         1000            :05 seconds





    • Edited by J S Nahil Monday, February 8, 2016 4:10 PM
    Monday, February 8, 2016 3:05 PM

Answers

  • Hi Joginder,

    Thanks for your friendly response.

    Really want to help you find a more appropriate forum.

    But one issue is that we have to make sure that which one really impacts the performance.

    Like my previous reply, we have to make sure that whether it is related to the windows/VS Environment, the project code itself or other.

    For example, if it is related to the code, you could use the profiler tool to analyze the functions of the code, and then you could know that which method really impacts the performance, you could share main code which really impacts the performance in the developing forum using a new thread, maybe the WPF forum would be better, so the WPF developer could provide you better workaround.

    But if it is not the code issue, you would think about improving your Environment configurations or others.

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 10, 2016 2:16 AM
    Moderator

All replies

  • Hi J S Nahil,

    Actually this forum is to discuss the VS IDE usage, for the performance issue, it is hard for us to provide the solution directly, but maybe I could provide the path for you.

    Generally it would be related to the Windows Environment, the system configurations, the project code itself.

    For the Environment issue, you could close all third party processes or tools and make sure that your windows is free in task manage.

    For the system configurations issue, maybe you could run the same app in other machine which has a better the configurations.

    For the project code issue, one idea is that you could use the VS profiler tool to really analyze your code.

    https://msdn.microsoft.com/en-us/library/ms182372.aspx

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 9, 2016 9:10 AM
    Moderator
  • Hi Jack,

    Thanks for that.

    Which forum should I have used? Can you please move it to the correct forum?

    I have used many techniques (C#, VB.NET, using a ViewModel, using background worker, direct update)  to update the progressbar. All show the same issue. 

    Regards,

    Joginder

     


    • Edited by J S Nahil Tuesday, February 9, 2016 9:31 AM
    Tuesday, February 9, 2016 9:31 AM
  • Hi Joginder,

    Thanks for your friendly response.

    Really want to help you find a more appropriate forum.

    But one issue is that we have to make sure that which one really impacts the performance.

    Like my previous reply, we have to make sure that whether it is related to the windows/VS Environment, the project code itself or other.

    For example, if it is related to the code, you could use the profiler tool to analyze the functions of the code, and then you could know that which method really impacts the performance, you could share main code which really impacts the performance in the developing forum using a new thread, maybe the WPF forum would be better, so the WPF developer could provide you better workaround.

    But if it is not the code issue, you would think about improving your Environment configurations or others.

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 10, 2016 2:16 AM
    Moderator