Solved

loop timers

Posted on 2004-09-20
4
250 Views
Last Modified: 2011-10-03
I'm trying to watch inputs from a port I can get this to work, What i need is to be able to have a master timer start when it sees ,lets say input one go high this time lets saw would run for 15 min, this would start a sub that also has a timer that would run for a varable input which could be from a textbox and while its running its loking for an input from any other input if it gets this input it will stop the sub and then wait for input one to go high again if no input is gotten in then it will times out and does the same and go back to looking for input one once more. This loop would run until the main timer has run out. I also need to be able to get the elasped time from the smaller timer and put it into a lable or textbox.
0
Comment
Question by:bassendoughboy
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:KGreg
KGreg earned 75 total points
ID: 12106434
Here's an example of a timed loop which will run every two minutes (120 seconds):


dim starttime as Date = Now

While Now.Subtract(starttime).TotalSeconds < 120

     ' Do some process here

     starttime = Now

End While

Hope this helps,

KGreg
0
 
LVL 3

Accepted Solution

by:
gillgates earned 175 total points
ID: 12107373
Imports System
Imports System.Threading

Public Class Test

    Shared waitTime As New TimeSpan(0, 0, 1)

    Shared Sub Main()
        Dim newThread As New Thread(AddressOf Work)
        While True
             newThread.Start()

             If newThread.Join( _
                  TimeSpan.op_Addition(waitTime, waitTime)) Then

                 'Do your work
             End If
       Loop
    End Sub

    Shared Sub Work()
        Thread.Sleep(waitTime)
    End Sub

End Class
0
 
LVL 3

Expert Comment

by:gillgates
ID: 12107381
of course after you do your work and you want to stop you have to "Exit Loop", my syntax for the while might be off.
0
 

Author Comment

by:bassendoughboy
ID: 12114441
I'm trying to follow what you are doing gillgates but not fully sure of it, Please bare with I have only been using VB for about 8 months. thanks.
Here is my best exapmle of what I'm doing.
program running
input comes in
statrs new sub (for 3 min)
when this sub starts it looks for another input, when it has input
it runs another sub (for 5 sec)
this looks for another input to stop this sub or time out if input stops sub elasped time is sent to a text box
if no input sub stops at end of time
eather way it goes back one level and waits for another input this goes on for the 3 min and then this timer stops
which goes back to the main program and stops it

 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - ReportViewer Windows Form many reports 2 24
vb.net 2 37
Change Format on Data when exporting to Excel 4 23
Get Top Visible Row of Datagridview 6 27
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now