我正在制作一个 VB.Net 2010 应用程序,我的应用程序中有一个调用 Web 服务的后台工作人员。如果 Web 服务返回数据,则后台服务会调用 Crystal 报表,然后将其打印出来。此时系统托盘图标重复。在 Web 服务运行结束时,后台工作人员执行 .Dispose() 。如果 Web 服务没有返回任何数据,则系统不会复制该图标。
你能帮忙的话,我会很高兴。谢谢!
后台工作人员代码:
Private Sub bwCheckForAlarms_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles bwCheckForAlarms.DoWork
Try
Try
'Checks for Alarms
If Not e.Cancel Then
CheckForAlarms(e)
Else
WrightRegistry("SeasionToken", "")
bwCheckForAlarms.Dispose()
End If
Catch ex1 As Exception
AddEventLogError(1013, ex1.ToString)
End Try
Try
'If on Checks for Announcesments
If Not e.Cancel Then
If ReadRegistry("PrintAnnouncements") = True Then
CheckForMessages(e)
End If
Else
WrightRegistry("SeasionToken", "")
bwCheckForAlarms.Dispose()
End If
Catch ex2 As Exception
AddEventLogError(1913, ex2.ToString)
End Try
Try
'Checks for Systems Alerts. NO shut off.
If Not e.Cancel Then
CheckForSystemMessages(e)
Else
WrightRegistry("SeasionToken", "")
bwCheckForAlarms.Dispose()
End If
Catch ex3 As Exception
AddEventLogError(1953, ex3.ToString)
End Try
Catch ex0 As Exception
AddEventLogError(1013, ex0.ToString)
Finally
bwCheckForAlarms.Dispose()
End Try
报告代码。
Public Function GenAlarmReportPrintOut(ByVal objAlarmNumber As String, ByVal objAlarmDateTime As String, ByVal objAlarmType As String, ByVal objAlarmAddress As String, ByVal objAlarmStatus As String, ByVal objAlarmCrossstreets As String, ByVal objStationAddress As String, ByVal objNotes As String, ByVal objDeptName As String, ByVal objProvidedby As String, ByVal objCommonName As String, ByVal objLogo As System.Drawing.Bitmap, ByVal objPDFFlag As Boolean, ByVal objAlarmDiscrition As String, ByVal objCopys As Integer) As Boolean
Dim ds As New dsReporting
Dim t As DataTable = ds.Tables.Add("Alarms")
Dim objRpt As New crpAlarmsPrnOutWithNaritive
Dim objPath As String
Dim objTimeStamp As String = Replace(DateTime.Now.ToString, "/", "_")
Dim r As DataRow
objTimeStamp = Replace(objTimeStamp, ":", "_")
'Sets up the Datatable
Try
Try
'check to see if their is a printer.
If ReadRegistry("SelectedPrinter") = "" Then
AddEventLogWarning(1006, "No printer was selected")
Return False
End If
Catch ex0 As Exception
AddEventLogError(1006, ex0.ToString)
Return False
End Try
Try
t.Columns.Add("AlarmNumber", Type.GetType("System.String"))
t.Columns.Add("AlarmDateTime", Type.GetType("System.String"))
t.Columns.Add("AlarmType", Type.GetType("System.String"))
t.Columns.Add("AlarmAddress", Type.GetType("System.String"))
t.Columns.Add("AlarmCross", Type.GetType("System.String"))
t.Columns.Add("AlarmStatus", Type.GetType("System.String"))
t.Columns.Add("TurnByTurn", Type.GetType("System.String"))
t.Columns.Add("Notes", Type.GetType("System.String"))
t.Columns.Add("DeptName", Type.GetType("System.String"))
t.Columns.Add("ProvidedBy", Type.GetType("System.String"))
t.Columns.Add("CommonName", Type.GetType("System.String"))
t.Columns.Add("AlarmDiscrition", Type.GetType("System.String"))
t.Columns.Add("Logo", System.Type.GetType("System.Byte[]"))
t.Columns.Add("AlarmGmap", System.Type.GetType("System.Byte[]"))
t.Columns.Add("Units", Type.GetType("System.String"))
t.Columns.Add("Naritive", Type.GetType("System.String"))
Catch ex1 As Exception
AddEventLogError(1005, ex1.ToString)
Return False
End Try
'Adds Data to table
Try
r = t.NewRow()
r("AlarmNumber") = objAlarmNumber
r("AlarmDateTime") = objAlarmDateTime
r("AlarmCross") = "Cross Street: " & objAlarmCrossstreets
r("AlarmStatus") = "Status: " & objAlarmStatus
r("AlarmType") = "Alarm Type: " & objAlarmType
r("AlarmDiscrition") = "Reported Alarm: " & objAlarmDiscrition
r("DeptName") = objDeptName
r("ProvidedBy") = objProvidedby
r("Notes") = "Notes: " & objNotes
If Not objCommonName = " " Then
r("CommonName") = "Common Name: " & objCommonName
Else
r("CommonName") = objCommonName
End If
r("Logo") = ToByteArray(objLogo)
If LCase(objAlarmAddress) = "demo" Then
r("AlarmAddress") = "Address: " & "xxx xxxxxx xxxxxxxx, xx xxxxx"
r("AlarmGmap") = ToByteArray(GetGmap(GetGeoCodeFromGoogle("76 old Glenham RD Glenham, NY"), 5040, 5160, 18, False))
r("TurnByTurn") = GetDrivingDirectionFromGoogle("901 main st fishkill, ny 12524", "76 old Glenham RD Glenham, NY")
Else
r("TurnByTurn") = GetDrivingDirectionFromGoogle(objStationAddress, objAlarmAddress)
r("AlarmAddress") = "Address: " & objAlarmAddress
r("AlarmGmap") = ToByteArray(GetGmap(GetGeoCodeFromGoogle(objAlarmAddress), 5040, 5160, 18, False))
End If
'***********************************
'Just here to fill the Datatable with a null
'****************************************************************************
r("Naritive") = ""
r("Units") = ""
'****************************************************************************
t.Rows.Add(r)
Catch ex2 As Exception
AddEventLogError(1006, ex2.ToString)
Return False
End Try
Try
objRpt.SetDataSource(ds.Tables(1))
objRpt.PrintOptions.PrinterName = ReadRegistry("SelectedPrinter")
objRpt.PrintToPrinter(objCopys, False, 0, 0)
Catch ex2 As Exception
AddEventLogError(1007, ex2.ToString)
Return False
End Try
Try
'Save as a pdf for uploading later.
If objPDFFlag Then
objPath = My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData & "\" & objTimeStamp & ".pdf"
objRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, objPath)
frmMain.ExportedCalls.Add(objPath)
End If
Catch ex3 As Exception
AddEventLogError(1008, ex3.ToString)
Return False
End Try
Return True
Catch ex4 As Exception
AddEventLogError(1009, ex4.ToString)
Return False
Finally
ds.Dispose()
t.Dispose()
objRpt.Dispose()
objPath = Nothing
r = Nothing
End Try
End Function