S
Steven Thomas
I am trying to write a windows service application to create reports.
This program reads from a MSSQL database where the report request are
placed. When it finds a new request a new thread is created and a sub
is called to run the report and save the snp file out of access. If I
slow the code down (with sleep statements) all of the reports run just
fine. How ever if I let it run at normal speed, it will create 2
threads wait for 1 sec and create 2 more (if there are request in the
queue)
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 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
----------------------------------------------------------
What happens is that I get a set of reports running, but only one ever
seems to finsih. I have put code in to write to the even log at
different points in the process. If a report is picked up, and never
finishes processing, it seems after looking at the event log that and
it never makes it inside of the sub.
Am I stepping on my on threads? if so can someone point me in the
right direction?
Thanks
This program reads from a MSSQL database where the report request are
placed. When it finds a new request a new thread is created and a sub
is called to run the report and save the snp file out of access. If I
slow the code down (with sleep statements) all of the reports run just
fine. How ever if I let it run at normal speed, it will create 2
threads wait for 1 sec and create 2 more (if there are request in the
queue)
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 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
----------------------------------------------------------
What happens is that I get a set of reports running, but only one ever
seems to finsih. I have put code in to write to the even log at
different points in the process. If a report is picked up, and never
finishes processing, it seems after looking at the event log that and
it never makes it inside of the sub.
Am I stepping on my on threads? if so can someone point me in the
right direction?
Thanks