473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Handling Threads

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
Dec 20 '06 #1
5 942
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

"tshad" <ts**********@ftsolutions.comwrote in message
news:uZ*************@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

Dec 20 '06 #2
Check the IsAlive property of the thread.

If myThread1.IsAlive = False then
'-- Do Something
End if
"tshad" <ts**********@ftsolutions.comwrote in message
news:uZ*************@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

Dec 21 '06 #3
"Mudhead" <no*****@yourhouse.comwrote in message
news:ea****************@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" <ts**********@ftsolutions.comwrote in message
news:uZ*************@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


Dec 21 '06 #4
Just reinitialize it:

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

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Mudhead" <no*****@yourhouse.comwrote in message
news:ea****************@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" <ts**********@ftsolutions.comwrote in message
news:uZ*************@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



Dec 21 '06 #5
"Mudhead" <no*****@yourhouse.comwrote in message
news:ek**************@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
>
"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>"Mudhead" <no*****@yourhouse.comwrote in message
news:ea****************@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" <ts**********@ftsolutions.comwrote in message
news:uZ*************@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



Dec 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
12
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
9
by: thiago777 | last post by:
Question details: VB .NET / threads / events / GUI Imagine the following situation: A method from object "A" creates "n" threads. Variables from these threads contains values that should...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.