Home All Groups Group Topic Archive Search About
Author
20 Dec 2006 7:23 PM
tshad
I am writing a Service that will start up some threads and I am trying to
find a way to tell if the threads are still running or not?

Is there a good program that will show that threads a service or program has
running?

Part of my code is:
*****************************************************************************
Protected Overrides Sub OnStart(ByVal args() As String)
  Dim oCredit1 As New CreditProcessor
  'LogInfo("CreditPoller Started")
  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())

  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
  oCredit1.ThreadNumber = "1"
  myThread1.Start()
End Sub

Class CreditProcessor
    Inherits CreditService
    Public ThreadNumber As String

    Public Sub ProcessCredit()
        If debugging Then
            DebugPoller("PollAndHandleCredit() Starting Thread Number: " &
ThreadNumber)
        End If

        If debugging Then
            DebugPoller("PollAndHandleCredit() Exiting Thread Number: " &
ThreadNumber)
        End If
    End Sub
End Class
*******************************************************************

The program just starts a thread that prints to a file that the thread is
starting and ending.

In this example, when the ProcesCredit() function exits - does that kill the
thread?

If not, how do I do that?

Thanks,

Tom

Author
20 Dec 2006 11:10 PM
Samuel Shulman
What about using variables as flags

These flags will be set to say True just before the thread finishes

The variable must be declared outside the thread

hth,
Samuel

Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:uZ1QXxGJHHA.320@TK2MSFTNGP06.phx.gbl...
>I am writing a Service that will start up some threads and I am trying to
>find a way to tell if the threads are still running or not?
>
> Is there a good program that will show that threads a service or program
> has running?
>
> Part of my code is:
> *****************************************************************************
> Protected Overrides Sub OnStart(ByVal args() As String)
>  Dim oCredit1 As New CreditProcessor
>  'LogInfo("CreditPoller Started")
>  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())
>
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "1"
>  myThread1.Start()
> End Sub
>
> Class CreditProcessor
>    Inherits CreditService
>    Public ThreadNumber As String
>
>    Public Sub ProcessCredit()
>        If debugging Then
>            DebugPoller("PollAndHandleCredit() Starting Thread Number: " &
> ThreadNumber)
>        End If
>
>        If debugging Then
>            DebugPoller("PollAndHandleCredit() Exiting Thread Number: " &
> ThreadNumber)
>        End If
>    End Sub
> End Class
> *******************************************************************
>
> The program just starts a thread that prints to a file that the thread is
> starting and ending.
>
> In this example, when the ProcesCredit() function exits - does that kill
> the thread?
>
> If not, how do I do that?
>
> Thanks,
>
> Tom
>
Author
21 Dec 2006 12:59 AM
Mudhead
Check the IsAlive property of the thread.

If myThread1.IsAlive = False then
'--  Do Something
End if


Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:uZ1QXxGJHHA.320@TK2MSFTNGP06.phx.gbl...
>I am writing a Service that will start up some threads and I am trying to
>find a way to tell if the threads are still running or not?
>
> Is there a good program that will show that threads a service or program
> has running?
>
> Part of my code is:
> *****************************************************************************
> Protected Overrides Sub OnStart(ByVal args() As String)
>  Dim oCredit1 As New CreditProcessor
>  'LogInfo("CreditPoller Started")
>  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())
>
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "1"
>  myThread1.Start()
> End Sub
>
> Class CreditProcessor
>    Inherits CreditService
>    Public ThreadNumber As String
>
>    Public Sub ProcessCredit()
>        If debugging Then
>            DebugPoller("PollAndHandleCredit() Starting Thread Number: " &
> ThreadNumber)
>        End If
>
>        If debugging Then
>            DebugPoller("PollAndHandleCredit() Exiting Thread Number: " &
> ThreadNumber)
>        End If
>    End Sub
> End Class
> *******************************************************************
>
> The program just starts a thread that prints to a file that the thread is
> starting and ending.
>
> In this example, when the ProcesCredit() function exits - does that kill
> the thread?
>
> If not, how do I do that?
>
> Thanks,
>
> Tom
>
Author
21 Dec 2006 6:01 PM
tshad
"Mudhead" <noth***@yourhouse.com> wrote in message
news:eadq%23sJJHHA.3872@TK2MSFTNGP06.phx.gbl...
> Check the IsAlive property of the thread.
>
> If myThread1.IsAlive = False then
> '--  Do Something
> End if

That makes sense.

In this case, if the thread exits normally such that the ThreadState =
Stopped,  can I just restart it doing something like:

  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
  oCredit1.ThreadNumber = "1"
  myThread1.Start()
  myThread1.Start()

Or

  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
  oCredit1.ThreadNumber = "1"
  myThread1.Start()
  oCredit1.ThreadNumber = "20"
  myThread1.Start()


Or do I need to reset the thread - something like:

  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
  oCredit1.ThreadNumber = "1"
  myThread1.Start()
  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
  oCredit1.ThreadNumber = "20"
  myThread1.Start()

Thanks,

Tom
Show quoteHide quote
>
> "tshad" <tscheider***@ftsolutions.com> wrote in message
> news:uZ1QXxGJHHA.320@TK2MSFTNGP06.phx.gbl...
>>I am writing a Service that will start up some threads and I am trying to
>>find a way to tell if the threads are still running or not?
>>
>> Is there a good program that will show that threads a service or program
>> has running?
>>
>> Part of my code is:
>> *****************************************************************************
>> Protected Overrides Sub OnStart(ByVal args() As String)
>>  Dim oCredit1 As New CreditProcessor
>>  'LogInfo("CreditPoller Started")
>>  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())
>>
>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>  oCredit1.ThreadNumber = "1"
>>  myThread1.Start()
>> End Sub
>>
>> Class CreditProcessor
>>    Inherits CreditService
>>    Public ThreadNumber As String
>>
>>    Public Sub ProcessCredit()
>>        If debugging Then
>>            DebugPoller("PollAndHandleCredit() Starting Thread Number: " &
>> ThreadNumber)
>>        End If
>>
>>        If debugging Then
>>            DebugPoller("PollAndHandleCredit() Exiting Thread Number: " &
>> ThreadNumber)
>>        End If
>>    End Sub
>> End Class
>> *******************************************************************
>>
>> The program just starts a thread that prints to a file that the thread is
>> starting and ending.
>>
>> In this example, when the ProcesCredit() function exits - does that kill
>> the thread?
>>
>> If not, how do I do that?
>>
>> Thanks,
>>
>> Tom
>>
>
>
Author
21 Dec 2006 6:24 PM
Mudhead
Just reinitialize it:

myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
oCredit1.ThreadNumber = "1"
  myThread1.Start()



Show quoteHide quote
"tshad" <tscheider***@ftsolutions.com> wrote in message
news:%23BMzXoSJHHA.4760@TK2MSFTNGP03.phx.gbl...
> "Mudhead" <noth***@yourhouse.com> wrote in message
> news:eadq%23sJJHHA.3872@TK2MSFTNGP06.phx.gbl...
>> Check the IsAlive property of the thread.
>>
>> If myThread1.IsAlive = False then
>> '--  Do Something
>> End if
>
> That makes sense.
>
> In this case, if the thread exits normally such that the ThreadState =
> Stopped,  can I just restart it doing something like:
>
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "1"
>  myThread1.Start()
>  myThread1.Start()
>
> Or
>
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "1"
>  myThread1.Start()
>  oCredit1.ThreadNumber = "20"
>  myThread1.Start()
>
>
> Or do I need to reset the thread - something like:
>
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "1"
>  myThread1.Start()
>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>  oCredit1.ThreadNumber = "20"
>  myThread1.Start()
>
> Thanks,
>
> Tom
>>
>> "tshad" <tscheider***@ftsolutions.com> wrote in message
>> news:uZ1QXxGJHHA.320@TK2MSFTNGP06.phx.gbl...
>>>I am writing a Service that will start up some threads and I am trying to
>>>find a way to tell if the threads are still running or not?
>>>
>>> Is there a good program that will show that threads a service or program
>>> has running?
>>>
>>> Part of my code is:
>>> *****************************************************************************
>>> Protected Overrides Sub OnStart(ByVal args() As String)
>>>  Dim oCredit1 As New CreditProcessor
>>>  'LogInfo("CreditPoller Started")
>>>  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())
>>>
>>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>>  oCredit1.ThreadNumber = "1"
>>>  myThread1.Start()
>>> End Sub
>>>
>>> Class CreditProcessor
>>>    Inherits CreditService
>>>    Public ThreadNumber As String
>>>
>>>    Public Sub ProcessCredit()
>>>        If debugging Then
>>>            DebugPoller("PollAndHandleCredit() Starting Thread Number: "
>>> & ThreadNumber)
>>>        End If
>>>
>>>        If debugging Then
>>>            DebugPoller("PollAndHandleCredit() Exiting Thread Number: " &
>>> ThreadNumber)
>>>        End If
>>>    End Sub
>>> End Class
>>> *******************************************************************
>>>
>>> The program just starts a thread that prints to a file that the thread
>>> is starting and ending.
>>>
>>> In this example, when the ProcesCredit() function exits - does that kill
>>> the thread?
>>>
>>> If not, how do I do that?
>>>
>>> Thanks,
>>>
>>> Tom
>>>
>>
>>
>
>
Author
21 Dec 2006 7:34 PM
tshad
"Mudhead" <noth***@yourhouse.com> wrote in message
news:ekyIM1SJHHA.4928@TK2MSFTNGP06.phx.gbl...
> Just reinitialize it:
>
> myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
> oCredit1.ThreadNumber = "1"
>  myThread1.Start()

That was what I thought.  It seemed that when I just just redid the
myThread1.Start() without reinitializing it was freezing.  Just wanted to
make sure.

Thanks,

Tom
Show quoteHide quote
>
>
>
> "tshad" <tscheider***@ftsolutions.com> wrote in message
> news:%23BMzXoSJHHA.4760@TK2MSFTNGP03.phx.gbl...
>> "Mudhead" <noth***@yourhouse.com> wrote in message
>> news:eadq%23sJJHHA.3872@TK2MSFTNGP06.phx.gbl...
>>> Check the IsAlive property of the thread.
>>>
>>> If myThread1.IsAlive = False then
>>> '--  Do Something
>>> End if
>>
>> That makes sense.
>>
>> In this case, if the thread exits normally such that the ThreadState =
>> Stopped,  can I just restart it doing something like:
>>
>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>  oCredit1.ThreadNumber = "1"
>>  myThread1.Start()
>>  myThread1.Start()
>>
>> Or
>>
>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>  oCredit1.ThreadNumber = "1"
>>  myThread1.Start()
>>  oCredit1.ThreadNumber = "20"
>>  myThread1.Start()
>>
>>
>> Or do I need to reset the thread - something like:
>>
>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>  oCredit1.ThreadNumber = "1"
>>  myThread1.Start()
>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>  oCredit1.ThreadNumber = "20"
>>  myThread1.Start()
>>
>> Thanks,
>>
>> Tom
>>>
>>> "tshad" <tscheider***@ftsolutions.com> wrote in message
>>> news:uZ1QXxGJHHA.320@TK2MSFTNGP06.phx.gbl...
>>>>I am writing a Service that will start up some threads and I am trying
>>>>to find a way to tell if the threads are still running or not?
>>>>
>>>> Is there a good program that will show that threads a service or
>>>> program has running?
>>>>
>>>> Part of my code is:
>>>> *****************************************************************************
>>>> Protected Overrides Sub OnStart(ByVal args() As String)
>>>>  Dim oCredit1 As New CreditProcessor
>>>>  'LogInfo("CreditPoller Started")
>>>>  myLog.WriteEntry("Demo Service Started @ " & TimeStamp())
>>>>
>>>>  myThread1 = New Thread(AddressOf oCredit1.ProcessCredit)
>>>>  oCredit1.ThreadNumber = "1"
>>>>  myThread1.Start()
>>>> End Sub
>>>>
>>>> Class CreditProcessor
>>>>    Inherits CreditService
>>>>    Public ThreadNumber As String
>>>>
>>>>    Public Sub ProcessCredit()
>>>>        If debugging Then
>>>>            DebugPoller("PollAndHandleCredit() Starting Thread Number: "
>>>> & ThreadNumber)
>>>>        End If
>>>>
>>>>        If debugging Then
>>>>            DebugPoller("PollAndHandleCredit() Exiting Thread Number: "
>>>> & ThreadNumber)
>>>>        End If
>>>>    End Sub
>>>> End Class
>>>> *******************************************************************
>>>>
>>>> The program just starts a thread that prints to a file that the thread
>>>> is starting and ending.
>>>>
>>>> In this example, when the ProcesCredit() function exits - does that
>>>> kill the thread?
>>>>
>>>> If not, how do I do that?
>>>>
>>>> Thanks,
>>>>
>>>> Tom
>>>>
>>>
>>>
>>
>>
>
>