Improve Windows Forms performance

This post is particularly for me as I always forgot those great tips and hard to find them back in MSDN Magazine or other resources, so I figure by putting them here will end up using them more also dear reader enjoy them too I'm sure you will find something you don't know or forgot a while ago.

fire your application faster

You can accomplish this by many ways starting with not populating the databoud controls in the load event directly instead have them on serrate thread so they don't block the UI while they linking to data source and rendering.

If you are using .NET 2.0 then you pleased with the new BackgroundWorker component that will delegate the work into background thread - will talk in details about BackgroundWorker in other post .

Now the most important part which is will boost your application startup is using native image generator NGen which is available with .NET Framework SDK since version 1.1 at least.

couple of days ago I have attended session about improving application startup performance by NGen within MDC presented by Surupa Biswas Program Manager on CLR Team and with the demo she showed us the difference between launching Microsoft Expression Blend with and without NGen images like the difference between shooting a bullet and throwing it and this also speak of a seprate post.

faster UI and Controls rendering

Always use BeginUpdate() and EndUpdate() to supress repaiting the controls while it's collection changing like the case of ListBox and ComboBox.

The neat trick i wouldn't thought of before by Milena Salman is when you hard code the data binding to a control is to assign the Control.ValueMemebr first then Control.DataSource couse assining the data source first will couse the control to repopulate.

Also notice that if you add controls at runtime, change or resize any existing controls will couas the parent control to fire Control.Layout event, so be sure to use SuspendLayout and ResumeLayout on the parent control when playing with the child controls.

Don't lean much on garbage collector

Not becouse GC will let you down but for instant finalizing managed resourses within your code is less expensive by letting GC do the job also don't forget to use the using keyword with unmanaged resources, if you do finalize an unmanaged resource by yourself call the GC.SuppressFinalization to save a GC cycle.

Published Sat, Feb 10 2007 1:52 AM by Adel Khalil

Comments

# re: Improve Windows Forms performance

Monday, April 02, 2007 10:37 PM by Manolis

Cool...

# re: Improve Windows Forms performance

Saturday, April 07, 2007 4:27 AM by Anaklets

Nice

# re: Improve Windows Forms performance

Sunday, April 08, 2007 10:35 AM by Epameinondas

Cool}Cool!

# re: Improve Windows Forms performance

Sunday, April 08, 2007 3:37 PM by Metrophanes

Interesting...

# re: Improve Windows Forms performance

Sunday, April 08, 2007 4:07 PM by Carolos

Nice...

# re: Improve Windows Forms performance

Saturday, April 14, 2007 10:21 PM by Vaggelis

interesting

# re: Improve Windows Forms performance

Monday, July 09, 2007 1:44 PM by Spiridon

Nice

# re: Improve Windows Forms performance

Monday, July 09, 2007 8:14 PM by Cosmo

Cool!

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 1:07 AM by George

Cool!

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 4:49 AM by Aris

interesting

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 7:09 AM by Stratis

Nice

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 11:43 AM by Lazaros

Cool.

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 4:16 PM by Thanos

interesting

# re: Improve Windows Forms performance

Tuesday, July 10, 2007 5:03 PM by Aleksiu

Sorry :(

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 4 and 6 and type the answer here: