Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Service Threading 1

Status
Not open for further replies.

SQLScholar

Programmer
Joined
Aug 21, 2002
Messages
2,127
Location
GB
Hey all,

I have this code:

Code:
Public Class NetworkAudit
    Dim Computername As String
    Dim running As Boolean
    Dim SQLConn As New ADODB.Connection

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.

        Const iTIME_INTERVAL As Integer = 60000      ' 60 seconds.
        Dim oTimer As System.Threading.Timer

        System.IO.File.AppendAllText("C:\AuthorLog.txt", "AuthorLogService has been started at " & Now.ToString() & vbCr)

        System.Threading.Thread.Sleep(20000)
        Dim tDelegate As Threading.TimerCallback = AddressOf EventAction
        oTimer = New System.Threading.Timer(tDelegate, Me, 0, iTIME_INTERVAL)

    End Sub

    Public Sub EventAction(ByVal sender As Object)
        System.IO.File.AppendAllText("C:\AuthorLog.txt", "AuthorLogService fires EventAction at " & Now.ToString() & vbCr)
        Call GetComputerInfo()
    End Sub

Now.... If the action is running already, i dont want it to run again. So getcomputers looks something like this

Code:
public sub getcomputers()
     If running = true then exit sub
     running = true
....OTHER CODE.......
Running = FALSE
end sub

Now unfortunately what seems to happpen is if the thread gets called while the thread is still running, it never runs the thread again.

How can i stop this happening? Effectively what i need is it to be able to run every X mins but if its already running then to not run. Or even something that only starts to trigger when its completed?

Any ideas? TIA

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
If you're going to be using this service just to write out to a log file every so often, then would you even need the thread timer? Why not just use the server timer?
 
It does more then that :-) just an example.

How do i use a server timer?

Dan

----------------------------------------
Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Dr. Seuss

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top