1

An application written in C# (Forms) is slowing down after some time (especially after waking up from sleep mode but also after like 30 minutes).

The application has the following structure:

enter image description here

The main panel changes as Button 1 or Button 2 are pressed. If Button 2 is clicked then a submenu as well as a subpanel is shown in the actual panel:

enter image description here

Interestingly, the app only needs extremely long to switch between Panel 1 and Panel 2 (that is if Button 1 or Button 2 is pressed). Once Button 2 is pressed and the panel is loaded, the switching between the subpanels (if Button 2a, 2b and 2c is pressed) is fast.

As Davin Tryon suggested in his answer to this post >Long running application slows down< I have checked for CPU, Memory, Disk and Network.

enter image description here

But these values don't seem to high to me...

Edit 03/23/13 6:11 p.m.: DasKrümelmoster asked for the switching code between Button/Panel 1 and Button/Panel 2:

activePanel.Hide();
activePanel = getPanelFromSelectedMenuElement(selectedMenuElement); // would return "panel2";

The same is basically done when switching between the sub-panels.

Community
  • 1
  • 1
libjup
  • 4,019
  • 2
  • 18
  • 23
  • Could you provide some of the "switching code" in Button 2 ? – DasKrümelmonster Mar 23 '13 at 16:57
  • See in the OP (edit 1) – libjup Mar 23 '13 at 17:17
  • +1 Indeed there is. I have removed all the timers from my application and now it runs smoothly. How can I release all the unmanaged resources? I tried to dispose all my objects but that did not solve the problem... – libjup Mar 23 '13 at 21:08
  • If you have VS Premium or Ultimate, you may try the *Code analysis* feature, especially the Microsoft.Reliability rules. If you can, share the timer code. To locate the error set the timers to shorter intervals and disable one at a time. – DasKrümelmonster Mar 23 '13 at 22:08

4 Answers4

0

You could look at using Red Gate Antz profiler )http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/) to check for any issues with memory etc. You will have a 14 day evaluation period too.

Also, maybe look at using Windows Performance counters against the application : http://www.codeproject.com/Articles/8590/An-Introduction-To-Performance-Counters

Christian Phillips
  • 18,399
  • 8
  • 53
  • 82
0

That can be unrelated to C#, winforms or your application. Windows may partially swap your application's memory to disk, because it was needed for other applications. When you access parts of the application after a long delay, swapped memory would be loaded back from disk, and that can take some time.

alex
  • 12,464
  • 3
  • 46
  • 67
  • How could I prevent that? Also, I think it has to do something with my application since no other apps are running (there is enough "free" CPU and memory). It simply gets slower after about 30 minutes... – libjup Mar 23 '13 at 17:10
0

In case you create the controls on demand at runtime: The creation of controls is slow, while hiding/showing them is sufficiently quick. You may shift the waiting time to the start of the application as it is less noticeable and create everything at startup.

See this control to help designing pages without showing the pages at runtime: https://stackoverflow.com/a/6954785/1974021

Community
  • 1
  • 1
DasKrümelmonster
  • 5,816
  • 1
  • 24
  • 45
  • I create them once when the application is started. That is pretty fast. But after some time the application gets slower and slower but no new controls are created. – libjup Mar 23 '13 at 17:08
0

Your question may not contain enough information for people to answer.

There some critical things:

  1. What's the approach that you append the controls on the main panel

  2. Did you dispose the child controls appended to the main panel? And how?

  3. According to the very less information of you code

    activePanel.Hide();
    activePanel = getPanelFromSelectedMenuElement(selectedMenuElement);
    

    Would the next time getPanelFromSelectedMenuElement return the same instance of previously hidden panel? If not, did you dispose the unreferenced panel?

  4. Whats the code level hierarchy of management of the controls?

You would need to provide this information to people that you can get a helpful answer. Or maybe you will just find the cause by reviewing the design.

If those are all no problem, and as you mentioned is would not be caused by CPU loading, memory usage, page swapping, disk accessing and network flowing; there is only one thing that you did not mention about: the graphic card performance.

Ken Kin
  • 4,503
  • 3
  • 38
  • 76