Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,
I have two ComboBox one in a Win Form and the other in an User Control.
I am trying to populate the Items using the AddRange method, using the same data array for both ComboBox. But the execution time for the ComboBox in Form is 4ms while the one in user control is 450ms.
Can anyone please let me know if they faced similar problem?

Code:
//Form: takes 4ms
C#
StartTimer();
            this.comboBox_labelActivationConfiguration.Items.AddRange(
            valuesSWCalibration.Keys.ToArray());
EndTimer();


//User Control: takes 450ms
C#
StartTimer();
           this.comboBox_calibrationLableToleranceOff.Items.AddRange(
           valuesSWCalibration.Keys.ToArray());
EndTimer();


Thanks,
Aniket
Posted
Comments
BillWoodruff 5-Dec-14 5:38am    
Timing results in .NET can vary greatly depending on which objects/methods you use to measure duration with, whether the code to be timed is pre-jitted, etc.; if you describe your methods ... which Timer object are you using ? ... then we can give you feedback.

Also: what is the Type of the Key in valuesSWCalibration ?
aniketnimse 8-Dec-14 1:47am    
I am using the Stopwatch Class and the Keys are Strings.
public void StartTimer()
{
stopwatch1.Reset();
stopwatch1.Start();
}
public void EndTimer()
{
stopwatch1.Stop();
MessageBox.Show("Time taken: " + stopwatch1.ElapsedMilliseconds + "ms");
}
Rob Philpott 5-Dec-14 5:42am    
Just because its in user control should make no difference. Also, see here for one possible reason:
http://stackoverflow.com/questions/10617551/combobox-items-addrange-performance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900