CPU Usage #2

Dec 1, 2014 at 11:22 AM
This library is great, but something has been bothering me since I started using it. CPU. A while back I noticed this problem and thought wow, WPF doesn't do a very good job keeping idle. I found out how to adjust the animation timeline and posted about it here:
https://mui.codeplex.com/discussions/437495

The problem is this makes the app choppy which is annoying. I just looked into this again because it has been driving me crazy and guess what? The problem is the indeterminate progress bar that is shown while content is loading. Ahhhh!!! IsIndeterminate is set to True, so it never ends. (try it out, set it to false and see the cpu go away). The fix? I looked at it for a minute and realized IsIndeterminate="{TemplateBinding IsLoadingContent}" would work and it does (it stops the animation). Fixed!!! Nope. What's strange is once you set IsIndeterminate=True, you can't stop the cpu it consumes by setting it to False. WPF defect? I'm going to look into this further tomorrow, but if anyone has information on this I'd appreciate it.
Dec 1, 2014 at 7:37 PM
I also found this: https://mui.codeplex.com/workitem/21208 (fixed by 110094)

Looks like I'm behind. Is anyone else still seeing the issue?
Dec 1, 2014 at 8:14 PM
The only way I could get the cpu to go away was to remove the progress bar. So here's what I did. I gave the grid in the frame containing the progress bar a name "LayoutRoot" and I also gave the ProgressBar a name "LoadingContentProgress". I then made sure all calls to set the content loading property used the IsLoadingContent property instead of calling SetValue directly. Then I added a setter to the IsLoadingContent property. Now when content is loading, the progress bar is added, when it's not, the progress bar is removed. A little ugly, but the CPU problem is gone. Here's the code:
    private Grid m_LayoutGrid;
    private ProgressBar m_LoadingContentProgressBar;
    /// <summary>
    /// Gets a value indicating whether this instance is currently loading content.
    /// </summary>
    public bool IsLoadingContent
    {
        get { return (bool)GetValue(IsLoadingContentProperty); }
        set
        {
            if (null == m_LayoutGrid)
            {
                m_LayoutGrid = (Grid)GetTemplateChild("LayoutRoot");
            }
            if (null != m_LayoutGrid)
            {
                if (null == m_LoadingContentProgressBar)
                {
                    m_LoadingContentProgressBar = (ProgressBar)GetTemplateChild("LoadingContentProgress");
                    if (null != m_LoadingContentProgressBar)
                    {
                        m_LayoutGrid.Children.Remove(m_LoadingContentProgressBar);
                    }
                }
                if (null != m_LoadingContentProgressBar)
                {
                    m_LoadingContentProgressBar.IsIndeterminate = value;
                    if (true == value)
                    {
                        m_LayoutGrid.Children.Add(m_LoadingContentProgressBar);
                    }
                    else
                    {
                        m_LayoutGrid.Children.Remove(m_LoadingContentProgressBar);
                    }
                }
            }
            SetValue(IsLoadingContentPropertyKey, value);
        }
    }
Coordinator
Dec 1, 2014 at 9:06 PM
The fix for workitem 21208 included the following change in the default ModernFrame style: IsIndeterminate="{TemplateBinding IsLoadingContent}"

The fix has been included in MUI 1.0.6 (the latest release). Is it possible you are not using the latest version, or not using the default style?
Dec 1, 2014 at 9:46 PM
Edited Dec 2, 2014 at 7:31 AM
I have this fix (change set 110094), the problem is the cpu problem still happens when IsIndeterminate is set to true and then back to false. To reproduce, never set IsIndeterminate to true and look at the CPU (hardcode to false). Then set it to true, then false (put the fix back in). The CPU is higher. In my project I have 3 of these progress bars using IsIndeterminate. On my machine with 12 logical processors, with change set 110094, after they all go from true to false, the cpu hovers around 1-2%. With the code above (remove the progress bar completely, then add when loading) the cpu moves between 0 to 0.25.

Thanks
Coordinator
Dec 2, 2014 at 7:25 AM
Definitely worth investigating, thanks for your time and proposed solution. I'll see if and how this will end up the source
Dec 2, 2014 at 7:29 AM
No problem, thanks for your great work.