【发布时间】:2013-12-27 14:55:00
【问题描述】:
我在尝试关闭仍在 VB.NET 应用程序内的 ReportViewer 中呈现的报表时遇到问题。当我尝试关闭仍然呈现的报告(超过 600 页的报告)时,它有时会看似关闭报告,但会挂起整个应用程序(包括最小化/最大化功能),但仍会在任务管理器中显示为“正在运行”。
我已经实现了CancelRendering 函数,但这似乎只在报告将首先正确关闭的情况下才有帮助。我已经尝试了各种不同的超时值,包括“-1”和“0”,但没有任何区别。此错误唯一不变的是当报告挂起应用程序时,CancelRendering 返回“False”。
这是运行 WinForms.ReportViewer 的 ReportBase 类的 sn-p:
Private Sub ReportBase_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Dim parent As MainForm
parent = Me.ParentForm ' Get the parent form of this child
' If there is only one child left and this child is closing then show the explorer bar
If parent.MdiChildren.GetLength(0) = 1 Then
parent.UltraExplorerBar1.Show()
parent.HomeToolStripMenuItem.Visible = False
MainForm.Panel2.Visible = True
End If
End Sub
Private Sub ReportBase_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim millisecondsTimeout As Integer = 100 'waits for the report to cancel rendering
Dim returnValue As Boolean
returnValue = ReportViewer2.CancelRendering(millisecondsTimeout)
MessageBox.Show(returnValue.ToString)
End Sub
Private Sub ReportBase_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With ReportViewer2
'Get reports from remote server
.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote
.ServerReport.ReportServerUrl = New System.Uri(ReportServer)
End With
End Sub
编辑 1: 有件事我忘了提。我检查了我的线程,当报告挂起我的应用程序时,“渲染”线程保持打开状态。
此外,当 CancelRendering 设置为“-1”时,报表永远不会关闭。应用程序只是挂起,报告仍处于打开状态。
编辑 2:
仅当我在“Printlayout”又名ReportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout) 中打开报告时才会发生这种情况。当报表正常打开时,它会立即加载所有 413 页。当以“PrintLayout”加载时,报告会非常缓慢地一一加载每个页面(在此模式下超过 600 个)。我认为这与退出正在加载每个页面的线程有关。
加载到常规模式时我无法收到错误。
我会在报表服务器上运行探查器会话,但不幸的是我目前没有访问权限。如果我确实获得了访问权限,我将更新结果。
编辑 3:
当报告正确关闭时(并且 CancelRendering 正常工作)我得到“报告处理被取消”并且CancelRendering 返回 true
当报表在关闭前没有停止渲染时,它会在CancelRendering触发后继续渲染并返回一个False。
我发现的另一件事是,如果我关闭整个应用程序而不仅仅是报告,该应用程序将关闭但仅作为任务管理器中的一个进程保持打开状态。这让我觉得关闭渲染线程确实是一个问题。当应用程序挂起时,线程也没有位置。
【问题讨论】:
标签: vb.net reporting-services ssrs-2008 reportviewer