S
Stewart Berman
Windows XP Pro SP3 with all patches
Visual Studio 2005 with all patches
..Net 2.0
I have an application which runs starts a BackgroundWorker task the is supposed to run until either
the user clicks on a Stop button in the foreground GUI which signals a cancel to the
BackgroundWorker task or the system shuts down.
After running for approximately two and a half days the BackroundWorker task exited without being
asked to. The trace log indicates implies that there was an unhandled exception as a number of
lines are missing between the last normal trace output and the BackgroundWorker task ending trace
lines. The trace wrapper was not involved as there is code immediately after the last regular trace
statement that appears to not have been executed or that threw an unhandled error:
TraceWriteLineIf(cvarTraceSwitch.TraceInfo, Format$(Now(), "yyyyMMdd HH:mm:ss.fff:
") & "Converting to bitmap: " & sFilePathName)
sFilePathNameSave =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\Wallpaper1.bmp"
img = Image.FromFile(sFilePathName)
img.Save(sFilePathNameSave, System.Drawing.Imaging.ImageFormat.Bmp) <== This was
not done.
If the above code (in a class instantiated by the BackgroundWorker task) threw an unhandled error
there should have been a messagebox on the scrren -- there wasn't any. (The execution of the method
in the class is not in a Try block in the BackgroundWorker_DoWork method.)
I pressed the Stop button on the GUI and got the following trace log entries:
20090717 12:36:04.687: btnStop_Click Tracing Started
20090717 12:36:04.687: StopSlideShow Tracing Started
20090717 12:36:04.687: ShutDownBackgroundTask Tracing Started
20090717 12:36:04.750: Dispose Tracing Started
20090717 12:36:04.750: Dispose Tracing Ended
20090717 12:36:04.750: ShutDownBackgroundTask Tracing Ended
20090717 12:36:04.750: StopSlideShow Tracing Ended
20090717 12:36:04.750: btnStop_Click Tracing Ended
I pressed the Start button and the BackgroundWorker task appeared to start correctly and begin
processing and logging.
It appears there was some type of error thrown that, instead of popping up an error message dialog
box set the Cancel flag of the BackgroundWorker class. Any explaination of what happened would be
appreaciated.
Pertinent details follow:
The code controlling the BackgroundWorker task is:
If (cvarTraceSwitch.TraceInfo) Then
TraceWriteLine(Format$(Now(), "yyyyMMdd HH:mm:ss.fff: ") &
System.Reflection.MethodBase.GetCurrentMethod.Name & " Tracing Started")
TraceIndent()
End If
CBackgroundWorker = CType(sender, BackgroundWorker)
lMemoryInUseStarting = MemoryInUse()
dataSet = LoadData(CType(e.Argument, DataSet))
CWallpaper = New Wallpaper()
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal
Do While (Not CBackgroundWorker.CancellationPending)
<snip>
If (CBackgroundWorker.CancellationPending) Then
e.Cancel = True
ElseIf (0 <> Interlocked.Exchange(cvarReload, 0)) Then
dataSet.Dispose()
dataSet = Nothing
dataSet = LoadData(CType(e.Argument, DataSet))
End If
Loop
CBackgroundWorker = Nothing
CWallpaper = Nothing
dataRow = Nothing
dataSet = Nothing
If (cvarTraceSwitch.TraceInfo) Then
TraceUnindent()
TraceWriteLine(Format$(Now(), "yyyyMMdd HH:mm:ss.fff: ") &
System.Reflection.MethodBase.GetCurrentMethod.Name & " Tracing Ended")
End If
The do loop does not contain an "Exit Do" statement nor an "Exit Sub" statement. There are two
points in the applicatoin code that call the BackgroundWorker classes AsynchCancel method. On is in
the Dispose method of the BackgroundWorker class and the other is in the Stop button handled by the
Foreground form. Both include trace statements. The trace log file does not include trace
statements from either one.
The trace log includes:
20090717 07:03:02.328: Converting to bitmap: C:\Common\SlideShow\IMG_2287.JPG
<expected trace lines missing>
20090717 07:03:02.718: CBackgroundWorker_RunWorkerCompleted Tracing Started
20090717 07:03:02.718: OnRunWorkerCompleted Tracing Started
20090717 07:03:02.718: OnRunWorkerCompleted Tracing Ended
20090717 07:03:02.718: CBackgroundWorker_RunWorkerCompleted Tracing Ended
which implies the BackgroundWorker task ended normally.
The GUI has a Start and Stop button for starting and ending the BackgroundWorker task. The code in
the Start button disables itself and enables the Stop button. The code in the Stop button disables
itself and enables the Start button. When I checked the GUI the Start button was disabled and the
Stop button was enabled indicating that the Stop button's code had not been executed. The trace log
did not contain any messages from the Stop button code confirming that it had not been executed.
At 7:00 AM a daily incremental backup runs via Veritas BackupExec. The application had thrown an
unhandled exception at around that time last week because the trace log was in use so I put the
following wrapper around all Trace method calls:
Module TraceNoBlock
Private mconMILLISECONDSTIMEOUT As Integer = 100
Private mconMAXIMUMTRIES As Integer = 100
Private Sub SleepAndBeep(ByVal millisecondsTimeout As Integer)
Beep()
Thread.Sleep(millisecondsTimeout)
Beep()
End Sub
Public Sub TraceWriteLine(ByVal message As String)
TraceWriteLine(message, mconMILLISECONDSTIMEOUT)
End Sub
Public Sub TraceWriteLine(ByVal message As String, ByVal millisecondsTimeout As Integer)
Dim nTries As Integer = 1
Do While (nTries <= mconMAXIMUMTRIES)
Try
Trace.WriteLine(message)
Exit Do
Catch ex As Exception
SleepAndBeep(millisecondsTimeout)
nTries = nTries + 1
End Try
Loop
End Sub
<snip>
The above could cause a trace message to be lost but only if the trace log was locked for ten
seconds (100 tries x 100 millisecnds).
:
Visual Studio 2005 with all patches
..Net 2.0
I have an application which runs starts a BackgroundWorker task the is supposed to run until either
the user clicks on a Stop button in the foreground GUI which signals a cancel to the
BackgroundWorker task or the system shuts down.
After running for approximately two and a half days the BackroundWorker task exited without being
asked to. The trace log indicates implies that there was an unhandled exception as a number of
lines are missing between the last normal trace output and the BackgroundWorker task ending trace
lines. The trace wrapper was not involved as there is code immediately after the last regular trace
statement that appears to not have been executed or that threw an unhandled error:
TraceWriteLineIf(cvarTraceSwitch.TraceInfo, Format$(Now(), "yyyyMMdd HH:mm:ss.fff:
") & "Converting to bitmap: " & sFilePathName)
sFilePathNameSave =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\Wallpaper1.bmp"
img = Image.FromFile(sFilePathName)
img.Save(sFilePathNameSave, System.Drawing.Imaging.ImageFormat.Bmp) <== This was
not done.
If the above code (in a class instantiated by the BackgroundWorker task) threw an unhandled error
there should have been a messagebox on the scrren -- there wasn't any. (The execution of the method
in the class is not in a Try block in the BackgroundWorker_DoWork method.)
I pressed the Stop button on the GUI and got the following trace log entries:
20090717 12:36:04.687: btnStop_Click Tracing Started
20090717 12:36:04.687: StopSlideShow Tracing Started
20090717 12:36:04.687: ShutDownBackgroundTask Tracing Started
20090717 12:36:04.750: Dispose Tracing Started
20090717 12:36:04.750: Dispose Tracing Ended
20090717 12:36:04.750: ShutDownBackgroundTask Tracing Ended
20090717 12:36:04.750: StopSlideShow Tracing Ended
20090717 12:36:04.750: btnStop_Click Tracing Ended
I pressed the Start button and the BackgroundWorker task appeared to start correctly and begin
processing and logging.
It appears there was some type of error thrown that, instead of popping up an error message dialog
box set the Cancel flag of the BackgroundWorker class. Any explaination of what happened would be
appreaciated.
Pertinent details follow:
The code controlling the BackgroundWorker task is:
If (cvarTraceSwitch.TraceInfo) Then
TraceWriteLine(Format$(Now(), "yyyyMMdd HH:mm:ss.fff: ") &
System.Reflection.MethodBase.GetCurrentMethod.Name & " Tracing Started")
TraceIndent()
End If
CBackgroundWorker = CType(sender, BackgroundWorker)
lMemoryInUseStarting = MemoryInUse()
dataSet = LoadData(CType(e.Argument, DataSet))
CWallpaper = New Wallpaper()
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal
Do While (Not CBackgroundWorker.CancellationPending)
<snip>
If (CBackgroundWorker.CancellationPending) Then
e.Cancel = True
ElseIf (0 <> Interlocked.Exchange(cvarReload, 0)) Then
dataSet.Dispose()
dataSet = Nothing
dataSet = LoadData(CType(e.Argument, DataSet))
End If
Loop
CBackgroundWorker = Nothing
CWallpaper = Nothing
dataRow = Nothing
dataSet = Nothing
If (cvarTraceSwitch.TraceInfo) Then
TraceUnindent()
TraceWriteLine(Format$(Now(), "yyyyMMdd HH:mm:ss.fff: ") &
System.Reflection.MethodBase.GetCurrentMethod.Name & " Tracing Ended")
End If
The do loop does not contain an "Exit Do" statement nor an "Exit Sub" statement. There are two
points in the applicatoin code that call the BackgroundWorker classes AsynchCancel method. On is in
the Dispose method of the BackgroundWorker class and the other is in the Stop button handled by the
Foreground form. Both include trace statements. The trace log file does not include trace
statements from either one.
The trace log includes:
20090717 07:03:02.328: Converting to bitmap: C:\Common\SlideShow\IMG_2287.JPG
<expected trace lines missing>
20090717 07:03:02.718: CBackgroundWorker_RunWorkerCompleted Tracing Started
20090717 07:03:02.718: OnRunWorkerCompleted Tracing Started
20090717 07:03:02.718: OnRunWorkerCompleted Tracing Ended
20090717 07:03:02.718: CBackgroundWorker_RunWorkerCompleted Tracing Ended
which implies the BackgroundWorker task ended normally.
The GUI has a Start and Stop button for starting and ending the BackgroundWorker task. The code in
the Start button disables itself and enables the Stop button. The code in the Stop button disables
itself and enables the Start button. When I checked the GUI the Start button was disabled and the
Stop button was enabled indicating that the Stop button's code had not been executed. The trace log
did not contain any messages from the Stop button code confirming that it had not been executed.
At 7:00 AM a daily incremental backup runs via Veritas BackupExec. The application had thrown an
unhandled exception at around that time last week because the trace log was in use so I put the
following wrapper around all Trace method calls:
Module TraceNoBlock
Private mconMILLISECONDSTIMEOUT As Integer = 100
Private mconMAXIMUMTRIES As Integer = 100
Private Sub SleepAndBeep(ByVal millisecondsTimeout As Integer)
Beep()
Thread.Sleep(millisecondsTimeout)
Beep()
End Sub
Public Sub TraceWriteLine(ByVal message As String)
TraceWriteLine(message, mconMILLISECONDSTIMEOUT)
End Sub
Public Sub TraceWriteLine(ByVal message As String, ByVal millisecondsTimeout As Integer)
Dim nTries As Integer = 1
Do While (nTries <= mconMAXIMUMTRIES)
Try
Trace.WriteLine(message)
Exit Do
Catch ex As Exception
SleepAndBeep(millisecondsTimeout)
nTries = nTries + 1
End Try
Loop
End Sub
<snip>
The above could cause a trace message to be lost but only if the trace log was locked for ten
seconds (100 tries x 100 millisecnds).
: