ak...@nreca.org
unread,Feb 16, 2012, 3:45:05 PM2/16/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I have a service that has a thread that uses msmq. Service starts and
works fine but if I leave it run overnight it fails during the night.
This thread uses a system.timers.timer which expires every 60
seconds. When it fails it write the following to the eventlog:
Application: WindowsService1.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
at System.Messaging.Cursor.Finalize()
Can't figure out where this is coming from. Here is the main part of
my code:
Public Sub Starter()
WriteToEventLog("PendedEvent thread is starting....",
LogSource, EventLogEntryType.Information)
MailHelper = New EmailHelper
' Use the same Quiet Start and End times retrieved by the
main thread
MailHelper.QuietStart = QuietStart
MailHelper.QuietEnd = QuietEnd
' Process then sleep
If Not MQin.Equals(Nothing) Then
PendedTimer = New Timers.Timer
AddHandler PendedTimer.Elapsed, New
ElapsedEventHandler(AddressOf PendedTimerHandler)
CalcInterval(TimeIncrement)
PendedTimer.Start()
End If
End Sub
Protected Sub PendedTimerHandler(ByVal sender As Object, ByVal e
As ElapsedEventArgs)
' Handles the event when the timer expires
Dim Time_Span As TimeSpan = New TimeSpan(10000)
Dim ArriveTime As DateTime = Now
Dim SomethingInQue As Boolean = True
Dim M As Message = Nothing
Dim FirstLoop As Boolean = True
Dim Qcursor As Cursor = Nothing
AddMessage(ErrorMessage, "PendedHandler starting")
WriteToEventLog(ErrorMessage, LogSource,
EventLogEntryType.Information)
ErrorMessage = ""
Try
PendedTimer.Stop()
Qcursor = MQin.CreateCursor
' Tell the object we want the 'ArrivedTime' property when
we peek
MQin.MessageReadPropertyFilter.ArrivedTime = True
AddMessage(ErrorMessage, "Starting queue peek")
WriteToEventLog(ErrorMessage, LogSource,
EventLogEntryType.Information)
ErrorMessage = ""
' First, check the queue
Do While SomethingInQue
Try
If FirstLoop Then
MQin.Peek(Time_Span, Qcursor,
PeekAction.Current) ' This will fall to "catch" if nothing
in the queue
FirstLoop = False
Else
MQin.Peek(Time_Span, Qcursor, PeekAction.Next)
End If
' Check to see when it arrived in the queue
ArriveTime = MQin.Peek.ArrivedTime
Catch mqe As MessageQueueException
If mqe.MessageQueueErrorCode =
MessageQueueErrorCode.IOTimeout Then
' Tomeout occured so there are no messages to
process
SomethingInQue = False
AddMessage(ErrorMessage, "Nothing in queue")
WriteToEventLog(ErrorMessage, LogSource,
EventLogEntryType.Information)
ErrorMessage = ""
Exit Do
End If
Catch ex As Exception
SomethingInQue = False
AddMessage(ErrorMessage, "Error processing MSMQ
'peek'" & vbCrLf & vbCrLf & ex.Message)
Exit Do
End Try
Process_Pended_Event(MQin.Peek.Body.ToString)
' If it's more than two days old report it stagnate
If Not PreviousMessageRemoved Then
If ArriveTime.AddDays(2) < Today Then
' Let someone know we have a transaction that
is stuck because of no company
' But first find out if we've alrady sent a
message today
If CheckSent() Then
If Not AlreadySentToday Then
AddMessage(ErrorMessage, "NewHire: a
subgroup has not been found in the Xref table for more than two days")
UpdateEmailLastSent()
End If
End If
End If
End If
Loop
If ErrorMessage.Length <> 0 Then
MailHelper.SendSupportEmail(SQLcmd, ErrorMessage,
IsProd)
RecordEmail(MQin.Peek.Body.ToString)
End If
RestartTimer()
Catch ex As Exception
AddMessage(ErrorMessage, "PendedTimerHandler: Outer trap "
& vbCrLf & ex.Message)
End Try
End Sub
Anyone have any ideas?