borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Winsock & File transfer)Next Topic (Backslash in posts) New Topic New Poll Post Reply
AndreaVB Forum : Frequently Asked Questions : VB slowness problem
Poster Message
Teresa
Level: Guest


icon VB slowness problem

Hi,

I have written a VB program to run as a service on server. It seems to work well except for it slows down the server significantly.

This program needs to run all the time when the server is on. When I did is putting the main loop in the Form_Load() function so that it runs automatically when the program is started (without any event). I also disable the form so that it doesn't show an icon(or window) on the destop. I think this might be a very silly way to accomplish this, but this was the only way I came up when I first started. And now, I think it might be the Form_load() that's taking all the memory. Is there a better way to do this?

Thanks,
Teresa

28-05-2003 at 09:02 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: VB slowness problem

A VB Program can be just a module. And since no UI is visible, a form isn't needed anyway.

If you remove the forms you could also check the "Unattended execution" in the properties (not required though - just suppresses any error messages from being displayed to written to an event log), also you have to change the startup to Sub Main() and have a Private Sub Main() in a module.

[also]
(I have seen some problems with VB and Client Access (IBM) for AS400's, so there may be a conflict with another program, test it on a non-server if possible to see if there's the same problem, compare software, etc)

[Edited by JLRodgers on 28-05-2003 at 03:21 PM GMT]

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

28-05-2003 at 09:20 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150
icon Re: VB slowness problem

and on the topic of slowness...

whever i stop my program during debug, it flashed back to the coding screen and one by one loads up ALL the forms and modules. is there a way to disable these animations?

28-05-2003 at 10:18 PM
View Profile Send Email to User Show All Posts | Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem

Thanks, JLRodgers.

Teresa

29-05-2003 at 03:37 PM
| Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem -- more

Well, I changed my form_load() to sub main(). It's still using up 100% CPU on the server. Now, what else can I do?

Thanks,

Teresa

29-05-2003 at 05:12 PM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: VB slowness problem

well... what else is running on the server? and, what is the program doing, if you don't mind telling us all..  

____________________________
Been busy trying to take a second degree <--it's not working out...

29-05-2003 at 05:16 PM
View Profile Send Email to User Show All Posts | Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem -- code included

To help you to help me, here's some psudocode to demonstrate my algrithm. Maybe you can tell the problem from my psudocode.

sub main()

do while RunProgram
    if datediff("n", t1, now)>=1 then
         'do in a one-minute interval
         Go to DB1 get Values
         Process Values
         Store results into DB2
         t1=now
    end if
    Check RunProgram
loop
end sub

This seems to be a very simple program, but takes a lot a process. I need to find a way to make it less memory-consuming and less CPU-consuming.

Thanks,
Teresa

29-05-2003 at 05:34 PM
| Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem -- answers to vbgen

There are IIS, a couple OPC servers, SQL server, and a couple OPC data collectors. If it's not running the vb program, everything seems to be fine (0-2% CPU usage). When this VB program starts, CPU usage jumps to 100%, and everything seems to be very slow.

I think I will give it a few more tries if I hear some other suggestions from you. Otherwise, I may have to change the entire program into PERL or C++, which are not favorable in the company.

Thanks,
Teresa

29-05-2003 at 05:50 PM
| Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: VB slowness problem -- code included

quote:
Teresa wrote:
To help you to help me, here's some psudocode to demonstrate my algrithm. Maybe you can tell the problem from my psudocode.

sub main()

do while RunProgram
    if datediff("n", t1, now)>=1 then
         'do in a one-minute interval
         Go to DB1 get Values
         'how are you getting these values? through a dsn?
         Process Values
         'what kind of processing?
         Store results into DB2
         'Perhaps your connection may be the problem
         t1=now
    end if
    Check RunProgram
loop
end sub

This seems to be a very simple program, but takes a lot a process. I need to find a way to make it less memory-consuming and less CPU-consuming.

Thanks,
Teresa


also, sometimes... sometimes... it may be better to use a for..next, than a do...while statement...

try them, then tell me what's happening..




yo!!! other help will be appreciated! members?

____________________________
Been busy trying to take a second degree <--it's not working out...
29-05-2003 at 06:15 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: VB slowness problem

Two things:
Both of the below can get a program to go from 100% usage to under 5%. Your code runs without giving the system control. This should fix it.

1) Put in DoEvents
2) Use the Sleep API

As a general tip, I always have a

Do
    DoEvents
    'Stuff
Loop

whenever I have a do loop.

The below code is overkill... but if a routine does sometime that's outside your program, you can't control the processor usage.



'Declarations
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

'EX:
Do While RunProgram
    DoEvents
    If datediff("n", t1, now)>=1 then
         DoEvents
         Sleep 1
         'do in a one-minute interval
         Go to DB1 get Values

         DoEvents
         Sleep 1
         'how are you getting these values? through a dsn?
         Process Values

         DoEvents
         Sleep 1
         'what kind of processing?
         Store results into DB2

         DoEvents
         Sleep 1
         'Perhaps your connection may be the problem
         t1=now
    end if
    DoEvents
    Sleep 1
    Check RunProgram
Loop
End Sub


[Edited by JLRodgers on 29-05-2003 at 12:47 PM GMT]

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

29-05-2003 at 06:46 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem -- SOLVED!

WONDERFUL!!!

It worked! Thanks a lot! I really appreciate all your help!

THANKS!

Teresa

29-05-2003 at 08:37 PM
| Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: VB slowness problem

And for anyone who wonders... the DoEvents/Sleep API does make the VB program run a bit slower - normally not noticable, or if it is, the user won't care since they can actually do other things on the PC at the same time.

But that's to be expected since you're telling the program to wait until the system processes other things before continuing.

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

29-05-2003 at 08:56 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
Teresa
Level: Guest

icon Re: VB slowness problem

Great! JLRodgers! Thanks for the information. I did a little research on DoEvents and Sleep API just now. Here's a very helpful web site you can go to get more tips.
http://www.vb-helper.com/tips10.htm

Thanks again!
Teresa

29-05-2003 at 09:07 PM
| Quote Reply
Shock
Level: VB Lord


Registered: 30-03-2003
Posts: 150
icon Re: VB slowness problem

*bump*

;) can anyone answer me ?

thx.
]

[Edited by Shock on 29-05-2003 at 11:59 PM GMT]

29-05-2003 at 11:58 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1616
icon Re: VB slowness problem

Only have code windows (not forms) visible and it goes a lot quicker. Just have the code of recently modified code open and it's quicker still.

____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)

30-05-2003 at 01:41 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Frequently Asked Questions : VB slowness problem
Previous Topic (Winsock & File transfer)Next Topic (Backslash in posts) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder