Bryon Huffman
asked on
vb.net multithreading try catch abort the correct thread
Basically I have 18 threads that all run the same subroutine but are given different stored procedure names to run. This part works great, I am trying to do the catch part of the try catch and I have come to the conclusion that if a stored procedure errors I don't know how to tell the subroutine to abort the correct thread ?
so the question is how does the subroutine know the name of the thread that is calling it so that I can do some sort of "thread name".abort to stop the thread with the error.
so the question is how does the subroutine know the name of the thread that is calling it so that I can do some sort of "thread name".abort to stop the thread with the error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I guess I thaught that I needed to do more with thread in reference to an error being thrown.
I haven't been able to make it cause an error to test it yet but was trying to be pro-active
I haven't been able to make it cause an error to test it yet but was trying to be pro-active
Can you post the code so that we can see what you are talking about. Also is this BackgroundWorker objects or are you handling the threading yourself?
I think you are taking suitable steps with the try...catch logic, you could try to make it crash by passing a procedure name in that doesn't exist for example.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for Bryon_connexus's comment #a40004684
for the following reason:
I didn't need to post this question because it is being handled inside of the subroutine.
Accepted answer: 0 points for Bryon_connexus's comment #a40004684
for the following reason:
I didn't need to post this question because it is being handled inside of the subroutine.
erm - isn't that what I told you.
@Bryon_connexus, you would not have known that unless AndyAinscow had not posted the solution.
ASKER
Dim starttime As DateTime = Now
Dim newThread As New Thread(AddressOf DoWork)
newThread.Start("MakeAccou
Dim newThread1 As New Thread(AddressOf DoWork)
newThread1.Start("MakeAcco
Dim newThread2 As New Thread(AddressOf DoWork)
newThread2.Start("MakeachA
Dim newThread3 As New Thread(AddressOf DoWork)
newThread3.Start("MakeATMR
Dim newThread4 As New Thread(AddressOf DoWork)
newThread4.Start("makebase
Dim newThread5 As New Thread(AddressOf DoWork)
newThread5.Start("Makebase
Dim newThread6 As New Thread(AddressOf DoWork)
newThread6.Start("MakeDraf
Dim newThread7 As New Thread(AddressOf DoWork)
newThread7.Start("Makeemai
Dim newThread8 As New Thread(AddressOf DoWork)
newThread8.Start("MakeIndi
Dim newThread9 As New Thread(AddressOf DoWork)
newThread9.Start("MakeMemb
Dim newThread10 As New Thread(AddressOf DoWork)
newThread10.Start("MakeMem
Dim newThread11 As New Thread(AddressOf DoWork)
newThread11.Start("Makemem
Dim newThread12 As New Thread(AddressOf DoWork)
newThread12.Start("Makemem
Dim newThread13 As New Thread(AddressOf DoWork)
newThread13.Start("MakeMem
Dim newThread14 As New Thread(AddressOf DoWork)
newThread14.Start("MakeOwn
Dim newThread15 As New Thread(AddressOf DoWork)
newThread15.Start("MakePro
Dim newThread16 As New Thread(AddressOf DoWork)
newThread16.Start("MakePro
Dim newThread17 As New Thread(AddressOf DoWork)
newThread17.Start("MakePro
Public Shared Sub DoWork(ByVal data As Object)
'Dim spname As String
'Dim tname As String
'Dim split As String() = data.Split(New [Char]() {" "c, ","c, "."c, ":"c, CChar(vbTab)})
'spname = split(0)
'tname = split(1)
Dim sqlconnstring As String = My.Settings.datamartconnst
Console.WriteLine("Static thread procedure. Data='{0}'", data)
Try
Dim sqlConn As New SqlConnection(sqlconnstrin
Dim cmd As New SqlCommand
Dim myParm As SqlParameter = cmd.Parameters.Add("@RowCo
myParm.Direction = ParameterDirection.ReturnV
Dim reader As SqlDataReader
cmd.CommandText = data
cmd.CommandType = CommandType.StoredProcedur
cmd.Connection = sqlConn
cmd.CommandTimeout = 0
sqlConn.Open()
reader = cmd.ExecuteReader()
' Data is accessible through the DataReader object here.
sqlConn.Close()
If myParm.Value < 1 Then
MsgBox("Store procedure " & data & " Returned no records")
End If
Dim Recordsreturned As Integer = myParm.Value
Catch db1 As DataException
********** here is where I think I need to stop/abort the thread ***********
MsgBox(db1.InnerException.
Catch ex1 As Exception
********** here is where I think I need to stop/abort the thread ***********
MsgBox(ex1.InnerException.
End Try
End Sub