user2648958
user2648958

Reputation: 1

How to make a heavily populated C# Windows Form UI more responsive

I have Windows Form that I use for a trading application, which, of necessity, has to display a large amount of information updating very rapidly (4 times per second).

The Windows Form I'm using has lots of controls (over 150 buttons and textboxes), and 6 datagridviews with multiple rows to display the information.

I have using different threads to perform the time-consuming operations (HTTPRequests, and various mathematical operations), but I am still finding that the GUI feels sluggish. I've noticed, in particular, that when I add more controls to the Form, things slow down, even though these extra controls are really 'doing' anything.

Can anyone explain why the mere presence of extra controls should make the GUI less responsive and/or recommend a completely different approach? Maybe I shouldn't be using Windows Forms?

Thanks.

Upvotes: 0

Views: 986

Answers (2)

Tamar Solutions
Tamar Solutions

Reputation: 1

Your controls take a lot of memory and I wonder why you have so many, have you considered creating controls on the fly as and when needed. Double Buffering is a must but will not help if you are clogging up memory as it is for graphic display. You need to profile your program using performance counters to find out where the problem lies, are you disposing correctly for instance? Also are you using too many threads? Are you using the thread pool, if not you should be! Are your controls loaded with data? I will think some more but profiling is what you need to do next.

Upvotes: 0

Jens H
Jens H

Reputation: 4632

It is hard to say something concrete without knowing your code.

A few generic ideas:

  • From your description, it sounds to me, like your application is very busy with repainting all the controls. Try experimenting with SuspendLayout() and ResumeLayout() and Invalidate() only those Controls that really need repainting.
  • Check if DoubleBuffering is enabled on both the Form(s) and ChildControls, it should be activated for most controls by default. But make sure you have it on.
  • Depending on your used .NET Frameworkversion check if you can use async/ await features for keeping the responiveness up.
  • See article MSDN Magazine article "Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads". This one is a few days old, but still absolutely valid.
  • Some events are fired more often than you expect or need. Check those events that cause repainting of controls (i.e. this will be where you add values to be displayed to the user) if these fire too often.

Upvotes: 1

Related Questions