Tips For Boosting .NET WinForm Performance
In this MSDN article, tips were suggested for boosting .NET WinForm Performance and I summarized as follows.
- Load fewer modules at startup
- Precompile assemblies using NGen
- Place strong-named assemblies in the GAC
- Avoid base address collisions
- dumpbin can check the preferred base address of Dlls.
- Avoid blocking on the UI thread
- Perform lazy processing
- Some operations can be implemented in the Idle event and will be processed when applications are idle.
- Populate controls more quickly
- The following code snippet shows how to avoid constant repainting.
listView1.BeginUpdate();
for(int i = 0; i < 10000; i++)
{
ListViewItem listItem = new ListViewItem("Item"+i.ToString() );
listView1.Items.Add(listItem);
}
listView1.EndUpdate();
- The following code snippet shows how to avoid constant repainting.
- Exercise more control over data binding
- BindingSource can help improve performance.
this.bindingSource1.SuspendBinding();
for (int i = 0; i < 1000; i++)
{
tbl.Rows[0][0] = "suspend row " + i.ToString();
}
this.bindingSource1.ResumeBinding();
- BindingSource can help improve performance.
- Reduce repainting
- Use SuspendLayout method whenever possible to minimize the number of Layout events.
- Call Invalidate method and pass the area that needs to be repainted as an argument to Invalidate.
- Use double buffering
- Manage memory usage
- If controls are added and removed from WinForm dynamically, call Dispose on them. Otherwise, extra unwanted handles would be accumulated in the process.
- If controls are added and removed from WinForm dynamically, call Dispose on them. Otherwise, extra unwanted handles would be accumulated in the process.
- Use reflection wisely