473,789 Members | 2,441 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 StartGPReportSe rver()
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.poll db(arQueues(x),
arThreadCnts(0, c))
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
If CInt(dtReportTo Run.Rows.Count) > 0 Then
arThreadCnts(3, c) = 1
'CInt(arThreadC nts(3,c)) + 1
'READ THE DATA ABOUT THE REQUEST
Dim cAccessFunc as new clsAccessFuncti ons
Dim othread1 As New Thread(AddressO f
cAccessFunc.CAc cessSnapShot)

'Create the new thread
'SET THE PROPERTIES OF THE SUB
othread1.Name = CStr(arThreadCn ts(1,
c))
cAccessFunc.pQC onnectionString =
arQueues(x)
cAccessFunc.pIn putFileName =
CStr(dtReportTo Run.Rows(0).Ite m("InputFileNam e"))
.........
'Start the thread
othread1.start( )
End If
End If
c += 1
End While
c = 0
Thread.CurrentT hread.Sleep(100 0)
End While
Catch errorVariable As Exception
'Error trapping
cFunctions.Writ eEventLog("GPRe port Could not start : " &
CStr(System.Dat eTime.Now()) & " " & errorVariable.M essage.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 12994
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.

ProcessThreadRe ady("Threadnumb er")

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/manualreseteven t classes

Da

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

I have an application that creates mutliple thread like this

My code
------------------------------------------------------------------------
Private Sub StartGPReportSe rver(
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.poll db(arQueues(x)
arThreadCnts(0, c)
' IF THERE IS WORK TO BE DONE READ THE DAT
FROM THE REPORTQUEU
If CInt(dtReportTo Run.Rows.Count) > 0 The
arThreadCnts(3, c) =
'CInt(arThreadC nts(3,c)) +
'READ THE DATA ABOUT THE REQUES
Dim cAccessFunc as new clsAccessFuncti on
Dim othread1 As New Thread(AddressO
cAccessFunc.CAc cessSnapShot
'Create the new threa

'SET THE PROPERTIES OF THE SU
othread1.Name = CStr(arThreadCn ts(1
c)
cAccessFunc.pQC onnectionString
arQueues(x
cAccessFunc.pIn putFileName
CStr(dtReportTo Run.Rows(0).Ite m("InputFileNam e")
........
'Start the threa
othread1.start(
End I
End I
c +=
End Whil
c =
Thread.CurrentT hread.Sleep(100 0
End Whil
Catch errorVariable As Exceptio
'Error trappin
cFunctions.Writ eEventLog("GPRe port Could not start : " &> CStr(System.Dat eTime.Now()) & " " & errorVariable.M essage.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**********@p lanet.nl> wrote in message news:<ub******* *******@TK2MSFT NGP11.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.

ProcessThreadRe ady("Threadnumb er")

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(ByVa l DBType As String, ByVal ThreadName
As String)
2) at the end of the sub that does the work I raise that event
RaiseEvent ThreadDone(pDBT ype, vThreadName)
3) In my main code I have a sub to catch that event
Sub RptMSAThreadDon e(ByVal pDBType As String, ByVal pThreadName As
String) Handles cAccessFunc.Thr eadDone
RecoverThreadCn t(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.Thr eadDone, AddressOf RptMSAThreadDon e
Dim othread1 As New Thread(AddressO f cAccessFunc.CAc cessSnapShot)
.......

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 ProcessThreadRe ady("Threadnumb er") 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
4271
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 threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
5
2142
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 when I got two threads going at the same time. What I have is two text boxes (textBox1 and textBox2) and four buttons(cmdStartThread1, cmdStartThread2, cmdStopThread1, cmdStopThread2)
5
2325
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 threads are running. The problem i have is that i am experiencing sudden high CPU utilization that lasts for a couple of seconds, and i believe that i have managed to tie this down to occuring when the thread is terminated.
2
1666
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 showing all filetypes and icons. I have an object that has extension, desc (like Word Document) and then icon, which is nothing to start with. I have a collection object of these and when it is initialized it goes to
4
1725
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 work is by creating a dummy form with a timer. On the timer function I test if the number of threads are less than 10 then run the remaining ones. This is working fine, but I would like to know how to do it without the form. This is the code...
2
2313
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 I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
2
3741
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 mentioned to, as much clear as possible, give a picture in what environment the problems rise**** Hello experts! I would appreciate if you can address this problem I have and give a hint what could be wrong.
2
2268
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 divided the complete drawing into 3 parts..1st will be done by main thread and other two are done in these procedures - <1LongTimeTask <2LongTimeTask2 I have invoked the threads using below method. **************
0
3420
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 someone please correct it? I think it's full of errors or I've really wrong everything...:D import random import threading import time import audio #this is a mobile phone library! # This takes about n/3 seconds to run (about n/3 clumps of...
0
9511
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,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
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,...
1
7525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
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
5415
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
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
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.