Solved

Thread to monitor Threadstate of "Worker" threads.

Posted on 2013-06-27
2
550 Views
Last Modified: 2013-06-27
In my While statement below I kick off a thread for each loop through the process

The thread is called phoneWorkerThread

How do I wrap that so I can have one thread monitoring ALL the worker threads thread state?

I want to monitor this part
  Dim phoneWorkerThread As New Thread(AddressOf startPhoneMonitoring)
  phoneWorkerThread.Start(sendRow)


        Try
            'Som kind of messaging that process is initiated
            Me.Text = "HTTP POST STARTED"

            Dim threadCounter As Integer = 1

            While returnedPhoneTable.Rows.Count > 0
                'Declare string to hold comma seperated phone string from datatable
                Dim dataRowString As String = ""

                'Declare var for data row in loaded data table
                Dim row = returnedPhoneTable.Rows(0)

                'Populate datarow string
                dataRowString = row("phoneList").ToString()

                'Dev - Show comma seperated phone list
                'Debug.Write(vbCrLf + vbCrLf + "Phonelist this row: " & dataRowString)

                'Declare string() to handle split by comma
                Dim sites As String() = dataRowString.Split(","c)
                Dim sendRow As String = ""

                'For each phone number build the command line
                'And group together all 7 numbers
                For Each s As String In sites
                    'Get command for this particular phone 
                    postData = getCommandString(s)

                    'Append to sendRow with line break to send all 7 phones to monitor at once
                    sendRow = sendRow + postData + vbCrLf
                Next

                'Declare and start individual thread for each loop
                Dim phoneWorkerThread As New Thread(AddressOf startPhoneMonitoring)
                phoneWorkerThread.Start(sendRow)

                'Some kind of messaging that shows how many threads are running
                Me.Text = "HTTP POST Thread Count: " + threadCounter

                'increase counter for next loop
                threadCounter = threadCounter + 1

                'Remove datarow just sent from datatable
                returnedPhoneTable.Rows.RemoveAt(0)

                'Reset SendRow string
                sendRow = ""

                'Since telephoy vendor needs about 1/2 second to process each phone...give plenty of time before next process start.
                System.Threading.Thread.Sleep(7000)
            End While
        Catch ex As Exception
            Debug.WriteLine("Error on record " & ErrorOnLoopNumber & vbCrLf & ex.Message.ToString)
        End Try

Open in new window

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39281594
You would need to add these threads to some sort of collection (a List(of Thread) variable) at class level. Then start the monitoring thread after starting all other threads and adding them to this collection. Monitoring thread then goes through each thread in the collection and checks in ThreadState and if its anything other than Running then do something (like restarting it).
0
 

Author Closing Comment

by:lrbrister
ID: 39283043
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question