473,513 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multithreading vb.net - how do I tell when a thread is done

I have an application that creates mutliple thread like this:

My code:
-------------------------------------------------------------------------
Private Sub StartGPReportServer()
Try
'Dim some variables........
While IsRunning
' LOOP THROUGH THE AVAILABLE THREADS
' I HAVE AN ARRAY WITH A RECORD FOR EACH THREAD THE
APPLICATION
' CAN CREATE. IN THIS CASE 6
While c < threads
' CHECK TO SEE IF THERE ARE REPORTS TO BE RUN
If arThreadCnts(3, c) = 0 Then
'POLL THE QUEUE TO LOOK FOR WORK
dtReportToRun = cFunctions.polldb(arQueues(x),
arThreadCnts(0, c))
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
If CInt(dtReportToRun.Rows.Count) > 0 Then
arThreadCnts(3, c) = 1
'CInt(arThreadCnts(3,c)) + 1
'READ THE DATA ABOUT THE REQUEST
Dim cAccessFunc as new clsAccessFunctions
Dim othread1 As New Thread(AddressOf
cAccessFunc.CAccessSnapShot)

'Create the new thread
'SET THE PROPERTIES OF THE SUB
othread1.Name = CStr(arThreadCnts(1,
c))
cAccessFunc.pQConnectionString =
arQueues(x)
cAccessFunc.pInputFileName =
CStr(dtReportToRun.Rows(0).Item("InputFileName"))
.........
'Start the thread
othread1.start()
End If
End If
c += 1
End While
c = 0
Thread.CurrentThread.Sleep(1000)
End While
Catch errorVariable As Exception
'Error trapping
cFunctions.WriteEventLog("GPReport Could not start : " &
CStr(System.DateTime.Now()) & " " & errorVariable.Message.ToString)
End Try
End Sub


I have this setup to run 6 threads at a time. How can I tell when a
thread has finished?
Nov 20 '05 #1
5 12967
Hi Steven Thomas

U can use ThreadState property of the thread class and find out what is the current status of the thread. It is a enumeration of thread states. I hope this will work

With regards

Sadha Sivam S
Nov 20 '05 #2
Hi Steven,

Maybe others have other answers, however in your scenario I have a class
with at the end of every thread procedure the function.

ProcessThreadReady("Threadnumber")

I hope this helps,

Cor
Nov 20 '05 #3
Do you need to wait for all of your threads to finish? Then you could use Thread.Join. Alternatively your thread could raise an event or signal using the auto/manualresetevent classes

Da

----- Steven Thomas wrote: ----

I have an application that creates mutliple thread like this

My code
------------------------------------------------------------------------
Private Sub StartGPReportServer(
Tr
'Dim some variables.......
While IsRunnin
' LOOP THROUGH THE AVAILABLE THREAD
' I HAVE AN ARRAY WITH A RECORD FOR EACH THREAD TH
APPLICATIO
' CAN CREATE. IN THIS CASE
While c < thread
' CHECK TO SEE IF THERE ARE REPORTS TO BE RU
If arThreadCnts(3, c) = 0 The
'POLL THE QUEUE TO LOOK FOR WOR
dtReportToRun = cFunctions.polldb(arQueues(x)
arThreadCnts(0, c)
' IF THERE IS WORK TO BE DONE READ THE DAT
FROM THE REPORTQUEU
If CInt(dtReportToRun.Rows.Count) > 0 The
arThreadCnts(3, c) =
'CInt(arThreadCnts(3,c)) +
'READ THE DATA ABOUT THE REQUES
Dim cAccessFunc as new clsAccessFunction
Dim othread1 As New Thread(AddressO
cAccessFunc.CAccessSnapShot
'Create the new threa

'SET THE PROPERTIES OF THE SU
othread1.Name = CStr(arThreadCnts(1
c)
cAccessFunc.pQConnectionString
arQueues(x
cAccessFunc.pInputFileName
CStr(dtReportToRun.Rows(0).Item("InputFileName")
........
'Start the threa
othread1.start(
End I
End I
c +=
End Whil
c =
Thread.CurrentThread.Sleep(1000
End Whil
Catch errorVariable As Exceptio
'Error trappin
cFunctions.WriteEventLog("GPReport Could not start : " &> CStr(System.DateTime.Now()) & " " & errorVariable.Message.ToString
End Tr
End Su


I have this setup to run 6 threads at a time. How can I tell when
thread has finished

Nov 20 '05 #4
"Cor Ligthert" <no**********@planet.nl> wrote in message news:<ub**************@TK2MSFTNGP11.phx.gbl>...
Hi Steven,

Maybe others have other answers, however in your scenario I have a class
with at the end of every thread procedure the function.

ProcessThreadReady("Threadnumber")

I hope this helps,

Cor


Ok this is what I did to make it all work
1) in the class where the work is being done I create an event
Public Event ThreadDone(ByVal DBType As String, ByVal ThreadName
As String)
2) at the end of the sub that does the work I raise that event
RaiseEvent ThreadDone(pDBType, vThreadName)
3) In my main code I have a sub to catch that event
Sub RptMSAThreadDone(ByVal pDBType As String, ByVal pThreadName As
String) Handles cAccessFunc.ThreadDone
RecoverThreadCnt(pDBType, pThreadName)
End Sub
4) I linked the two together when I was setting up the thread
Dim cAccessFunc As New AccessFunc()
'ADD A HANDLER TO CAPTURE DATA BACK FROM THE THREAD
AddHandler cAccessFunc.ThreadDone, AddressOf RptMSAThreadDone
Dim othread1 As New Thread(AddressOf cAccessFunc.CAccessSnapShot)
.......

Well it works.
Nov 20 '05 #5
Hi Steven,

When I understand you well than that is almost the same as I do in the
section which does that ProcessThreadReady("Threadnumber") I sand you. It
looks if you had copied that routine which I did not send you. (I have also
two parameters and not one).

:-)

Cor
Nov 20 '05 #6

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

Similar topics

11
4228
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
5
2120
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
5
2312
by: MS Newsgroups | last post by:
Hi, I have an application that runs a timer and executes a method in a class as a new thread every 60 seconds, the thread takes 65 seconds to execute so there is a 5 second overlap when 2...
2
1644
by: SStory | last post by:
Here is the situation. I want to display Icons, Type of file etc from a file extension. Upon initial program load I may only need icons for certain files. But other operations will require...
4
1712
by: Manuel | last post by:
I have a long function that needs to be done 1000 times. I'm multithreading it, but I don't want to load them up all at once, instead load them 10 at a time. So far the only way I can get it to...
2
2297
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
2
3713
by: shonend | last post by:
**** sorry about the length of the message. If you can't read the whole thing and still willing to help, read the last 2 paragraphs where the main problem is described. The introduction story is...
2
2240
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
0
3410
luke14free
by: luke14free | last post by:
Hello, I was trying to run a multithreading example with python on my phone that lets me to record and play at the same time.I've found an example somewhere but, as expected it doesnt work,,,could...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
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...
1
7114
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...
1
5098
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4751
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...
0
3240
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...
0
3230
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1607
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 ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.