Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

dynamically adding controls and slow speed!!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ike - 23 Jul 2006 21:23 GMT
Hello,

I'm developing an application where the user gets the ability to choose how
the form looks like. What is shown, wich controls to use and all available
properties of those controls.
The data gets pulled from a database.

The only problem I have is the speed. When having a form with 500 controls
it takes about 7-8 seconds to show that form to the user. Which is too slow.

At first my guess was that the database was slowing the app down. Or the
looking up of the types and assembly loading for the controls it self.

But then I ran a little experiment. I created a form with one button on it
with the following event-handler.

void button1_click(object sender, EventArgs e)
{
 this.SuspendLayout();
 for (int i = 0; i < 1000; ++i)
 {
   Checkbox temp = new Checkbox();
   this.Controls.Add(temp);
 }
 temp.ResumeLayout();
}

I would say this is real basic stuff, but it turns out that this also needs
7 seconds to show the the new controls.

Is there any way I can speed up this kind of operation?

Best regards,
Ike Casteleyn
GAZ - 24 Jul 2006 07:47 GMT
Your code works just fine. I tested it on my development computer and it is
almost instantenious. Only changed:

temp.ResumeLayout();

into

this.ResumeLayout();

My computer is a Pentium 4 3.2GHz, 1GB RAM.

BR,

GAZ

> Hello,
>
[quoted text clipped - 33 lines]
> Best regards,
> Ike Casteleyn
ike - 24 Jul 2006 17:05 GMT
Hi Gaz,

Thanks for the response.

I have retested my app using the following code

       private void button1_Click(object sender, EventArgs e)
       {
           System.Diagnostics.Stopwatch sp =
System.Diagnostics.Stopwatch.StartNew();
           this.Cursor = Cursors.WaitCursor;
           this.SuspendLayout();
           for (int i = 0; i < 1000; ++i)
           {
               CheckBox temp = new CheckBox();
               this.Controls.Add(temp);
           }
           this.ResumeLayout();
           this.Cursor = Cursors.Default;
           sp.Stop();
           MessageBox.Show(sp.ElapsedMilliseconds.ToString());
       }

I just added the stopwatch stuff to have a clear look on the time to show
the controls.
On pc1 (p4 2.8ghz 1gb ram winxp) -> 2400 milliseconds
On pc2(amdxp 1700 512mb ram win2k) -> 4000 milliseconds.

Could you run this in your pc once again with the adjusted code. Just to
know what 'instantenious' is like timewise. I ran the app with only vs2005
open. Last time I probably had around 7 solutions open (maybe that ate a lot
of mem to go to 7 seconds).

Best regards,
Ike

> Your code works just fine. I tested it on my development computer and it is
> almost instantenious. Only changed:
[quoted text clipped - 48 lines]
> > Best regards,
> > Ike Casteleyn
GAZ - 25 Jul 2006 07:36 GMT
Hi Ike,

I've run your code and came up with a result of 1807. It seems that the
process itself is rather CPU intensive. I added a counter in the performance
monitor to follow application's percentage of processor's time and the
spikes were impressive. It seems that your application will be directly
dependent on the processor power of the target computer.

BR,

GAZ

> Hi Gaz,
>
[quoted text clipped - 90 lines]
>> > Best regards,
>> > Ike Casteleyn
ike - 25 Jul 2006 07:51 GMT
Hi Gaz,

Thanks for the info. Seems I won't be able to do anything then to improve.

Best regards,
Ike

> Hi Ike,
>
[quoted text clipped - 102 lines]
> >> > Best regards,
> >> > Ike Casteleyn
GAZ - 25 Jul 2006 14:37 GMT
Hi Ike,

Would your application really need forms with such large number of controls?
From my experience however advanced users are they start to get lost if the
form has more than 30ish controls. It is a large amount of visual
information to process at the same time, especially having in mind that the
users would have to scroll up and down to read parts of the form.

I don't know what kind of application you are building but I think that it
is a safe bet that users won't have more than a 100 controls per a form. It
would not be a good and useful user interface.

Another thing you might consider doing if you get stuck with a large number
of controls is to place them in different tabs. In that way you could
actually add controls to each tab separately once the user click on a
specific tab. That would slow-down a bit tab generation, but it would be
somewhat faster than add all controls at the same time.

BR,

GAZ

> Hi Gaz,
>
[quoted text clipped - 120 lines]
>> >> > Best regards,
>> >> > Ike Casteleyn
ike - 25 Jul 2006 19:51 GMT
Hi Gaz,

I know that too much controls are bad for user experience. We also develop
our static forms using tabs and such to take the feeling of a screen full of
controls (also to get data loading down).

Problem for us is that these forms are dynamic. The user decides what's on
the forms (the app pulls the info from a database) and we allready have some
with a form of 500 controls.
However I didn't give the possibility to have a tabcontrol to work with.
A solution might be found in that direction. Thanks for the tip.

Best regards,
Ike

> Hi Ike,
>
[quoted text clipped - 17 lines]
>
> GAZ

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.