473,657 Members | 3,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() 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 960
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**********@f tsolutions.comw rote in message
news:uZ******** *****@TK2MSFTNG P06.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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() 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.IsAli ve = False then
'-- Do Something
End if
"tshad" <ts**********@f tsolutions.comw rote in message
news:uZ******** *****@TK2MSFTNG P06.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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() 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*****@yourho use.comwrote in message
news:ea******** ********@TK2MSF TNGP06.phx.gbl. ..
Check the IsAlive property of the thread.

If myThread1.IsAli ve = 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(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1.Start ()

Or

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
oCredit1.Thread Number = "20"
myThread1.Start ()
Or do I need to reset the thread - something like:

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "20"
myThread1.Start ()

Thanks,

Tom
>
"tshad" <ts**********@f tsolutions.comw rote in message
news:uZ******** *****@TK2MSFTNG P06.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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() 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(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()

"tshad" <ts**********@f tsolutions.comw rote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
"Mudhead" <no*****@yourho use.comwrote in message
news:ea******** ********@TK2MSF TNGP06.phx.gbl. ..
>Check the IsAlive property of the thread.

If myThread1.IsAli ve = 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(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1.Start ()

Or

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
oCredit1.Thread Number = "20"
myThread1.Start ()
Or do I need to reset the thread - something like:

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "20"
myThread1.Start ()

Thanks,

Tom
>>
"tshad" <ts**********@f tsolutions.comw rote in message
news:uZ******* ******@TK2MSFTN GP06.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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() Exiting Thread Number: " &
ThreadNumbe r)
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*****@yourho use.comwrote in message
news:ek******** ******@TK2MSFTN GP06.phx.gbl...
Just reinitialize it:

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "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**********@f tsolutions.comw rote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>"Mudhead" <no*****@yourho use.comwrote in message
news:ea******* *********@TK2MS FTNGP06.phx.gbl ...
>>Check the IsAlive property of the thread.

If myThread1.IsAli ve = 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(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1.Start ()

Or

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
oCredit1.Thread Number = "20"
myThread1.Start ()
Or do I need to reset the thread - something like:

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "20"
myThread1.Start ()

Thanks,

Tom
>>>
"tshad" <ts**********@f tsolutions.comw rote in message
news:uZ****** *******@TK2MSFT NGP06.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("Credi tPoller Started")
myLog.WriteEntr y("Demo Service Started @ " & TimeStamp())

myThread1 = New Thread(AddressO f oCredit1.Proces sCredit)
oCredit1.Thread Number = "1"
myThread1.Start ()
End Sub

Class CreditProcessor
Inherits CreditService
Public ThreadNumber As String

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

If debugging Then
DebugPoller("Po llAndHandleCred it() 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
2468
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 a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
2
2134
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 database. This works fine. However, I attempt to notify the user when data accesses occur. The way I attempt to accomplish this is by changing the background color of a label on the form the user is looking at. I use red for when the database is...
12
428
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 a minute. The data received is logged in a SQL Server database. The only method I have found of reading each socket requires a thread for each connection which blocks waiting for data. This appears to be very inefficient as it will result in...
9
2106
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 be updated to a form (only when this form exists), one form can be shown/created for each thread. Thought the forms might not exist, the threads will be always running. I dont want to control the components (eg. labels) of the form from the threads...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.