VB.Net and CPU Usage Increasing

db , sharepoint , vb.net United Kingdom
  • 13 years ago

    I have developed a VB.Net program which interfaces to an OCR Reader

    The problem is that when it is running, the CPU stays at about 3-5% but the Mem Usage indicator in Windows Task Manager gradually increases every 2-3 secs till finally it crashes the machine over about 12hours

     Any Help would be appreciated

    Regards 

    splints

     

  • 13 years ago

    I presume you are closing all open connections and reader objects. It sounds like your objects are not being disposed of.

  • 13 years ago

    Thanks for your response 

    I am new to this VB game so am not sure how to check open connections and reader objects are closed

    I am using a timer to check for an input trigger every 3sec or so I think this is what is causing my problems

    How  can I check what you have said ie check that all open connections and reader objects are closing

     Regards

     

  • 13 years ago

    I'm no ocr whizz, and I imagine there may be issues if this connection is constantly open, and your timer is essentially a ticking timebomb.

    I'm not at my Dev computer today, although I will be tomorrow, and so if you still ahve problems and nonone has responded, stick another post.

    A simple way to open and close a connection is by inserting the USING keyword

    USING connection As New SqlConnection(GetConnection())

     END USING

    This will automatically close the connection when the procedure is passed out of.

    I'm not sure what your timer is checking, but if it is related to your ocr procedure, I would advise working with some other checking procedure. If you are working with a database, then you can work with the cache instead, and check the required column at a set time (triggers). I imagine every 3 seconds to be an extreme time to be checking an object, and would advise you let the server inform the client instead when the nature of an object has changed; perhaps by using Guid or timestamp objects.

  • 13 years ago

    Thanks Again for your response

    I use the timer to check if an input is ON on an IO board every 3 secs

    Once the tick event is active (ie every 3 secs) i dispose of the timer as follows:-

    TriggerSenseTimer.Enabled=False

    TriggerSenseTimer.Stop()

    TriggerSenseTimer.Dispose

    check input status

    IF Input is OFF Then Enable Timer Again as follows:-

    TriggerSenseTimer.Interval=3000

    TriggerSenseTimer.Enabled=True

    TriggerSenseTimer.Start()

     

    If  Input is ON Then keep timer disabled and execute code

    Once code has been executed, then timer is enabled again as above ready for next instance of input being ON

    Have you any other ideas how I could check the input state and act if the input is ON

     Regards

    splints

  • 13 years ago

    I've had a read of the class library, and put forward a few suggestions:

    The Windows.Forms.Timer() class is for single-threaded applications and does not interoperate too well with the form and are for simple timer operations. You seem to be working with a server process, and it is recommended you use the System.Timers.Timer() class. I have a feeling your timer is conflicting with the form. If this is not so, forgive my presumption.

    You should then use a event driven delegate to run the timer in the background.

    Declare an AddHandler statement and work through the process you are working with:

    Declare your boolean trigger as a public variable

    Private Input As Boolean = False

    Private timer1 As New System.Timers.Timer()

    Protected Sub TimerHandler(ByVal o As Object, ByVal e As EventArgs)

    If Input Then

     aTimer.Stop()

    aTimer.Enabled = True

    Else

    Input = False

    End Sub

     

    In the control of container that will run the timer create an AddHandler statement:

    Public Sub SomeControl()

     AddHandler timer1.Tick, AddressOf TimerHandler

    timer1.Interval = 3000

    timer1.Start()

    While Input = False

    ' If you want the form to repaint, call this method.

    Application.DoEvents()

    End Sub

     

    You will have to modify this to suit your puroposes, but I'm fairly certain this should be ok. To do a quick check, run the process, and CTRL+ALT+Delete to see the memory consumption on your app. If this fails, get back to me and we'll try something else.

  • 13 years ago

    Many thanks for your time.

    I will have a look at what you have suggested and get back to you

     

     

     

  • 13 years ago

    D'Scouser 

    Did you receive my email regarding this subject

     

     

  • 13 years ago

    I certainly did, and posted you a reply a couple of hours later to the return email, and I haven't received a failed to send from hotmail. So do you need me to send it again?

  • 13 years ago

    Please Re-Send If Possible

    I never received it - maybe your hotmail address is being filtered as junk mail at this end

    Could you try an alternative address

  • 13 years ago

    I don't have any other mail address, but I'm fairly certain it went, and I've added your name to the contacts list. So I think the problem is at your end. I've resent it to the address.

  • 13 years ago

    In that case could you re-send it

     Else, do you know of a way of attaching a zip file to a posting or private message

    Regards

     

  • 13 years ago

    I've sent it as an IM and is posted here somewhere, I don't know how you access it however.

  • 13 years ago

    Many Thanks for your detailed reply

     Will try to incorporate some of your thinking into the code as appropriate

    I will try and find a way of attached the code zip file ASAP and send it

    In the meantime, yes I di check for an output from the PLC to be ON which I then act on.

    I thought that checking the input every 3secs as opposed to being in a continual loop waiting for the input would use less resources.

    Once Again - Many Thanks

  • 13 years ago

     Do you want to Learn Sharepoint ???

    Learn Share Point freely

    http://hotsoftwareslist.blogspot.com/2007/10/learn-sharepoint-freely.html

    Do you want to learn PHP/.NEt/JAVA/ERP/SAP/...... ???

    Download EBooks Freely in .pdf,.chm formats and ready for interview questions....

    http://hotsoftwareslist.blogspot.com/2007/08/download-ebook.html
     

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”