I’ve been often asked how to improve performance of WinForms apps so here is the list of my top suggestions and further reading recommendations on how to speed up your Windows Forms applications:

  1. Reduce modules loaded by your application to increase start-up time. Remove all references from your project that are not used. Click here to read MSDN article on that on other techniques.
  2. Pre-compile your assemblies using NGEN when appropriate to decrease start-up time. Click here to read my short post with guidelines on when to consider doing this.
  3. Use native C++ Splash Screen that shows up immediately when your application is started. This will make your application appear to load faster. Click here to read and download C++ project with native splash screen. Native splash screens have such small memory footprint that they appear immediately.
  4. Don’t set BackColor=Transparent on your controls. Transparent color support in Windows Forms is terribly inefficient since it is not real transparency. Whenever you set BackColor=Transparent you incur additional Paint call on the parent control. As part of child control rendering, child control will first direct parent control to paint itself on it then child control will paint over that so it appears it is transparent. And this is repeated for every single control that has transparent background. Couple that with the next point and you have real slow-down.
  5. Reduce usage of gradients. Gradients whether linear or radial especially on large surfaces of screen are slow. I know they look good, but use solid colors whenever possible and you will see much better rendering performance. Especially on large panels.
  6. Reduce code in Form Load event. Use BackgroundWorker to offload work onto the different thread so your UI can load faster and feel snappier while you do other work.
  7. Delay Control Creation. Creating and populating controls takes lot of time, so if you can, delay it or do it on demand. For example, you can avoid creating controls on all pages of Tab Control right away and do so in either Appllication.Idle event or when that tab is selected from SelectedTabChanged event.
  8. Set DataSource last. When using data-binding set DataSource property last. If you set it before you set ValueMember or DisplayMemeber properties for bound controls, the data source will be re-queried to populate control each time these properties are set.
  9. Use SuspendLayout and ResumeLayout on parent controls and form to optimize layout changes. Bounds, Size, Location, Visible, and Text for AutoSize controls causes the layout changes. Note that you should call these methods when performing multiple layout changes and always on parent control of the controls that you are changing layout for.
  10. Use BeginUpdate and EndUpdate when adding multiple items to trees, grids and other controls that support this.
  11. Call Dispose() method on your forms once you are done with them. Most of the time developers forget to call Dispose() method on form they’ve shown using ShowDialog(). Make sure you always dispose your forms and controls to free up memory. Use handy using statement.
  12. Dispose() your graphic resources. If you are performing any custom drawing make sure you explicitly dispose your Pen, Brush, Image and other graphic resources once you are done with them. Using statement is good for this as well.

Do you have more tips for speeding up the WinForms application? Please share them in comments below.

Also check out the 2 Things You Can Do Today To Improve User Interface In Your Applications post for helpful UI tips.

Professional looking applications made easy with DotNetBar for WinForms, Silverlight and WPF User Interface components. Click here to find out more.

Related posts:

  1. DotNetBar for Windows Forms 8.2 released with Office 2010 and Windows 7 styles
  2. DotNetBar 6.0 goodness, Part 4, Ribbon MDI Merging
  3. DotNetBar for Windows Forms 7.1 Released
  4. DotNetBar for Windows Forms 8.6 Released
  5. TextRenderer.DrawText bug when drawing on bitmaps with ClearType