S
Steven Thomas
Ok
I have a multithreaded windows service application. This application
serves reports back to multiple web applications. This service can
run from 1-x reports (on different threads) at any given time. My
problem is once I start a thread running, if I need to abort the
thread, I don't know how to referance it?
My code:
Private Sub StartReportServer()
Try
' DIM MY LOCAL VARIABLES
......
' READ THE CONFIG FILE
.....
While IsRunning
'LOOP THROUGH THE ARRAY OF AVAILABLE THREADS YOU HAVE TO SERVICE
While c < threads
' CHECK TO SEE IF THIS THREAD IS RUNNING
If arThreadCnts(3, c) = 0 Then
'IF IT IS NOT RUNNING CHECK TO SEE IF THERE IS ANY
REPORTS WAITING BY POLLING THE QUEUE
dtReportToRun = cFunctions.polldb()
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
.....
' IF THE REPORT TYPE IS ACCESS CREATE SNAPSHOT
If vOutputFileType = "MSACCESS" Then
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)
' SET THE PROPERTIES OF THE CLASS
AND START NEW THREAD
.....
' START THREAD
othread1.start()
Else
'DO THE SAME FOR EXCEL
Dim cExcelFunc As New ExcelFunc()
End If
End If
Else
' CHECK STATUS OF REPORT TO SEE IF IT IS
TIMED OUT THEN ABORT THREAD
dtReportStatus = cFunctions.CheckRptStatus(
arQueues(x), CLng(arThreadCnts(3, c)))
If CStr(dtReportStatus.Rows(0).Item
("ProcessingState")) = "T" Then
***** HERE I WANT TO ABORT THE THREAD IF IT HAS BEEN SET
***** TO A STATUS OF T FROM THE FRONT END
End If
End If
c += 1
End While
c = 0
x += 2
End While
c = 0
x = 1
Thread.CurrentThread.Sleep(1000)
End While
End Try
End Sub
-----------------------------------------------------------
I have a multithreaded windows service application. This application
serves reports back to multiple web applications. This service can
run from 1-x reports (on different threads) at any given time. My
problem is once I start a thread running, if I need to abort the
thread, I don't know how to referance it?
My code:
Private Sub StartReportServer()
Try
' DIM MY LOCAL VARIABLES
......
' READ THE CONFIG FILE
.....
While IsRunning
'LOOP THROUGH THE ARRAY OF AVAILABLE THREADS YOU HAVE TO SERVICE
While c < threads
' CHECK TO SEE IF THIS THREAD IS RUNNING
If arThreadCnts(3, c) = 0 Then
'IF IT IS NOT RUNNING CHECK TO SEE IF THERE IS ANY
REPORTS WAITING BY POLLING THE QUEUE
dtReportToRun = cFunctions.polldb()
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
.....
' IF THE REPORT TYPE IS ACCESS CREATE SNAPSHOT
If vOutputFileType = "MSACCESS" Then
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)
' SET THE PROPERTIES OF THE CLASS
AND START NEW THREAD
.....
' START THREAD
othread1.start()
Else
'DO THE SAME FOR EXCEL
Dim cExcelFunc As New ExcelFunc()
End If
End If
Else
' CHECK STATUS OF REPORT TO SEE IF IT IS
TIMED OUT THEN ABORT THREAD
dtReportStatus = cFunctions.CheckRptStatus(
arQueues(x), CLng(arThreadCnts(3, c)))
If CStr(dtReportStatus.Rows(0).Item
("ProcessingState")) = "T" Then
***** HERE I WANT TO ABORT THE THREAD IF IT HAS BEEN SET
***** TO A STATUS OF T FROM THE FRONT END
End If
End If
c += 1
End While
c = 0
x += 2
End While
c = 0
x = 1
Thread.CurrentThread.Sleep(1000)
End While
End Try
End Sub
-----------------------------------------------------------