VB.NET sloooooooooow

I got a form with a calender on it, one full year, one small label for every day to set free days and such for a simple employee management application.
Actually, 12 months 7 days per week and at most 6 (sometimes partial) weeks in a month, that means 6x7x12 = 504 labels. I tried both creating at runtime and creating in desginer.
The redraw is very very slow.
I got the old VB6 app here and it's a lot faster.

This is no real big deal but it's anoying me.

Any idea how to solve this? I don't mean by removing controls or somehow splitting it over tabs or whatever. I mean specifically increase the speed of redraw. Or prevent redraw?? Would that still leave things working properly and can this be done?

Also a colleague has a big grid with Format stuff in the cells, also very slow. Can this be improved?

I don't want to spend much time on trying to solve this, I'm just hoping on some fairly simple solution, maybe disable certain features of the form, the labels or whatever.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I had (have) the same problem. I found that generating a native image helps a little bit.

open a cmd window and type

C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322>ngen "C:\ -path of .exe -"

this compiles a native image that makes the componenets load a bit faster.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NicoLaanAuthor Commented:
This is what I tried:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ngen "N:\EMP_Employees\bin\EMP_Employees.exe"
Unfortunetly I don't see any speed change.

Not sure if that was clear, my main problem is not starting the app, but when it's already running, I have the form, place another form (IE or whatever) in front, go back to my app and now the form is redrawn very slow.
At least slow for a 3GHz or something machine with 512 MB. A lot slower than VB6 app.
NicoLaanAuthor Commented:
Tried it again, your suggestion does give an improvement in speed only not where I was looking for it. SO didn't notice the first time.

The first loading of the form is clearly faster after this. Only when the form is already there it doesn't matter anymore.

So still thanks for the idea, I'll keep it in mind, but it's not completely what I was looking for.
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

NicoLaanAuthor Commented:
Oops, no, no (significant) speed change because of the native code, but a significant change because of running it outside the VS2005 IDE.

So, I'm sorry but it's back to my first conclusion again, your idea doesn't seem to help.

Still thanks for trying anyway
So if I understand you correct you are having problems redrawing the GUI when you make changes during runtime.

Can you post the code to the app?
Also I would check how much resources it uses. When the app is running ctrl, alt, del and see how much memeory it uses in the task manager.


NicoLaanAuthor Commented:
The memUsage is 21mb starting the app, goes to 24 when I open this slow form.
VM size goes from 17.5 (starting the app) to 19.7 (opened the slow form).

Also it's a lot slower when run from the VS IDE, the speed is acceptable when run from Windows without the VS 2005 IDE. But I do notice it's not very fast in redrawing the screen. It's like being behind a 486 using Windows 95 again.

Here is the significant part of the app.
Call DrawMonths in some init code of some form or even from a button click or something.
I also used a click handler called MonthLabelClick, below is one you can use for this purpose. Mine had somewhat more useful code but I don't think that matters.

  Private Sub DrawMonths()
    Dim day As Integer
    Dim dayR As Integer
    Dim dayC As Integer
    Dim month As Integer
    Dim monthR As Integer
    Dim monthC As Integer
    Dim monthX As Integer
    Dim monthY As Integer
    Dim lblDay As Label
    Dim index As Integer = 0

    For monthR = 0 To 1
      For monthC = 0 To 5
        monthX = monthC * 154 + 8
        monthY = monthR * 160 + 95
        day = 1
        For dayR = 0 To 5
          For dayC = 0 To 6
            lblDay = New Label
            lblDay.AutoSize = False
            lblDay.Location = New System.Drawing.Point(monthX + dayC * 22, monthY + dayR * 22)
            lblDay.Name = "txtDay" & month.ToString & "_" & (day + 1).ToString
            lblDay.Size = New System.Drawing.Size(20, 20)
            lblDay.TabIndex = day + 20
            lblDay.BorderStyle = BorderStyle.Fixed3D
            lblDay.BackColor = Color.White
            lblDay.TextAlign = ContentAlignment.MiddleCenter
            AddHandler lblDay.Click, AddressOf MonthLabelClick

            txtDays(index) = lblDay

            index += 1
            day += 1
        month += 1
      Next ' monthC
  End Sub

  Private Sub MonthLabelClick(ByVal sender As Object, ByVal e As System.EventArgs)
  End Sub
NicoLaanAuthor Commented:
The app is not unacceptable slow, it's just that I would not expect to see a redraw happening on a fast machine like this.
I'd expect the form to just show up with all controls on it.
I also notice this slugishnes with big grids and it annoys me.

Now I think the fact that it's .NET also makes things a lot slower. Not just the code not being native but more.
Still I wonder if somehow I can improve the speed.
The compile to native is an idea but doesn't help in my case.
But maybe there are more things to do.
Bob LearnedCommented:
I am using VB.NET 2003, and I tried your code in a simple form, and it drew just fine.  Are you doing something special here?

NicoLaanAuthor Commented:
Not really.
It does draw and when not from inside VS IDE it runs ok, just the screen IO of VB.NET in general seems slow to me. I'll try it in a single test app later to see if it's related to anything other than I send you.
Now have to go home for the weekend. (so sorry to have to go home ;-)

A few things that show it clearly to me:
1 Show the form, put another app in front, now back to the form. Now I see the form redraw.

2 Show the form. Drag another app in front of it and move it around for a while with the option "Show windows content while dragging" on. Now I see Window of the other app dragging behind on my slow form.

3 Try 1 or 2 but now with this form started from within VS in debugging mode.

Yes, I know it sounds like I'm searching here.
I noticed the slowness when I was debugging in VS. Saw the form redraw after I came back to the form from another app. The other things I noticed later.

It's also no big deal, only I hope there is some easy way to make screen IO go faster.

Every app I ever wrote always ran slower from the dev suite. Once you run the exe it is noticable faster. Do you have any other re-draw issues when you run your computer? One thing I always do to my computers that run Windows XP is

right click My Computer -> Properties -> Advanced Tab -> click the Settings button in the Performance groupbox -> select the Adjust for best performance radiobutton.

From here you can check the bottom 3 checkboxes in the list below the radio buttons and the XP look will stay the same.

Another I also do is right click on the desktop -> properties - > Click the Appearance tab -> and click the Effects button

Here I uncheck all.

I know this is a little outside of the VB.NET scope but I have had trouble in the past due to XP's bloatedness and this improves performance alot.

Good Luck

NicoLaanAuthor Commented:

You're right, it is slightly of topic, still no harm in checking.
However I'm a big fan of tweaking to my preferred (fast) settings.
The settings you describe are some of the 1st things I do with a new XP.
And also remove themes and other crap.
And yes that dramatically increases speed I feel.

I specifically have redraw / draw issues with a few .NET apps.
Like this one with many labels and another with a big grid with lots of format stuff in the columns.
I really admit it's not the easiest thing for a computer, but this was already fast enough with old fashioned win32 programming, even VB6, on a 233MHz machine with 4MB video card or something.
So why oh why is it so noticably slow on a brand new 3GHz (or something close) machine.

Okay, again, it's not really time consuming slow, I don't have to actually wait, but I do clearly see it happen.
I can live with it, but it's just like an itch I want to scratch, it's bugging me. I'm easily bugged I do admit.

I tried your code and found it worked ok. I even tried the things you mentioned and it still rendered fast.
Try to cut the amount of labels in half and see if it changes the speed. ( I know you need all of the labels but try it just to see if it makes a difference) I know I have written a few apps in the past that uses tabbed interfaces and they always work a little "slower". If you have more code to post please do so and I will try to run the full app.

What version of .NET do you have installed? What happens if you take the .exe and put it on another computer and run it?

NicoLaanAuthor Commented:
Hi zac,

Thanks for all your efforts. Now in the easter weekend so have to wait till tuesday to try more.
It's .NET 2.0.

I'll try to set up a 2nd app with also only the lables, same test as you've tried and with half the labels.
See if I can see a difference.

What I also already tried is put the labels on screen without click handler but this time from the designer so not created in code. Lot's of copy paste actions.
Now the app was noticable faster.

When I was copy pasting the controls I also found the whole visual studio to be quite slow. When I selected the days for the last 6 months and pressed delete I saw them being removed one by one. It took more than a few seconds. Thinking back I'd say at least 10, but closer to 20 or 40 seconds to remove 6x7x6 days from the form at design time.
Maybe it's related, mayvbe it's not.
NicoLaanAuthor Commented:
Made a seperate test app myself with the code, as provided before, under a button.

Made 2 changes to make the effect more visible.
   lblDay.Size = New System.Drawing.Size(21, 21) ' slightly bigger labels now, to fit 2 digits.
   lblDay.Text = day.ToString
So at least there is some text in each label.

Now on my computer it takes close to 2 seconds to fill the whole screen when I switch between apps when in debugging mode from Visual Studio.

When I just run the exe from Explorer it's a lot faster. I can still see the redraw, but it's fairly fast, slightly less than 1/2 a second I guess.

When I drag another form in front I clearly see the redraw. I can "blank" almost all the labels by dragging another big form in front. It takes almost 1 second to fill them all again.

Also did a test with making all the labels at design time in this app. Just create 1 label for 1 day, copy paste it to get more days. When I copy pasted the 1st 6 months to get the whole year, this took over 1 minute to finish!!
For the rest this version had about the same timings.
NicoLaanAuthor Commented:
And to delete all 6x7x12 day labels in the designer from the form again it took over 1 minute.
NicoLaanAuthor Commented:
Hi Zac and Bob,

I decided to close the Q, no new tips coming in anymore.

For me the problem hasn't been solved, however the accepted answer might give people with a simular problem some help.
Because of that I didn't want to just delete the Q and I also wanted to show my appreciation for the effort taken.
Thanks again for trying to help.

Kindest regards,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.