Code Optimization -Compact Framework
Reply
![]() |
|
|
From:
Anand Kumar
|
Hi Group,
Here is my thought on this...
If you look at the code generated for windows form is not always optimized properly you need to consider few thing to make it more optimize for better performance for example you can optimize the form initialize code or you can improve the form load performance .
The following are the best practices to be consider for improve the performance of your application
Eliminate Unnecessary Calls : Yu can improve the performance of loading the form by reducing the numbers of calls made during the form initializing lets say you have a textbox control on the windows form and the code generate in Initialization method is
this.myTextBox.Location = new Point(20,30); this.myTextBox.Size = new Size(90,26);
it can be optimize by making a single call as below
this.myTextBox.Bounds = new Rectangle(20,30,90,26);
The other way to improve the performance through create the controls top-down. You can optimize the initialize method for better performance by initialize the controls in the control tree top-down. Lets say if you have a panel control with many controls in it, create the panel first, and then add the controls to the panel. Also, setting the parent property of the control instead of adding to the Controls collection can improve performance. For example, consider adding a textbox to a panel's control collection:
// Create a new panel and textbox control Panel panel1 = new Panel(); TextBox textBox1 = new TextBox(); // Set the Text property of the TextBox control textBox1.Text = "My Text"; // Add the TextBox to the Panel's control collection panel1.Controls.Add(this.textBox1); // Add the Panel to the Form's control collection this.Controls.Add(panel1); ... // Add subsequent controls here
Optimizing this code snippet using the top-down and parenting techniques results in the following snippet:
// Create a new panel and textbox control Panel panel1 = new Panel(); TextBox textBox1 = new TextBox(); // Parent the Panel to the current Form this.panel1.Parent = this; // Parent the TextBox to the Panel this.textBox1.Parent(this.panel1); // Set the Text property of the TextBox control textBox1.Text = "My Text"; ... // Add subsequent controls here
Together these can make a big difference with a deeply nested control hierarchy.
Optimizing the code in the InitializeComponent method by creating the controls top-down and re-parenting them resulted in a performance improvement .
For more information http://mobility.microsoftdev.com/
Cheers Anand http://spaces.msn.com/members/anandkumar
|
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|