[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

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.
0
NicoLaan
Asked:
NicoLaan
  • 11
  • 4
2 Solutions
 
saculCommented:
Hello,

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.

Cheers

Zac
0
 
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.
0
 
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
0
 
saculCommented:
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.

Thanks,

Zac
0
 
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
            Me.Controls.Add(lblDay)

            txtDays(index) = lblDay

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

  Private Sub MonthLabelClick(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show("Clicked")
  End Sub
0
 
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.
0
 
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?

Bob
0
 
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.
0
 
saculCommented:
Hello,

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

Zac
0
 
NicoLaanAuthor Commented:
Zac,

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.
0
 
saculCommented:
Hello,

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?

Zac
0
 
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.
0
 
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.
0
 
NicoLaanAuthor Commented:
And to delete all 6x7x12 day labels in the designer from the form again it took over 1 minute.
0
 
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,

Nico
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 11
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now