私は 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