从ReportViewer关闭渲染报告有时会挂起应用程序

时间:2013-12-27 14:55:01

标签: vb.net reporting-services ssrs-2008 reportviewer

我在尝试关闭仍在VB.NET应用程序内的ReportViewer中呈现的报表时遇到问题。当我尝试关闭静态渲染报告(报告超过600页)时,有时会看到关闭报告但挂起整个应用程序(包含最小化/最大化功能),但仍然在任务管理器中显示为“正在运行”。

我已经实现了CancelRendering功能,但这似乎只对报告首先正确关闭的情况有所帮助。我已经为超时尝试了各种不同的值,包括“-1”和“0”,但没有什么区别。这个错误唯一不变的是当报告挂起应用程序CancelRendering返回“False”时。

以下是运行WinForms.ReportViewer的ReportBase类的片段:

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

works

当报告在关闭之前没有停止渲染时,它会在CancelRendering触发后继续渲染并返回False。

does not work

我发现的另一件事是,如果我关闭整个应用程序而不是仅关闭报告,应用程序将关闭但仅作为任务管理器中的进程保持打开状态。这让我觉得关闭Render线程确实是一个问题。当应用程序挂起时,线程也没有位置。

threads

1 个答案:

答案 0 :(得分:0)

这是我解决这个问题的临时方式。即使这使我的应用程序不再挂起,我也很想知道这个问题的ACTUAL解决方案。

Private Sub ReportBase_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim millisecondsTimeout As Integer = 0 'waits for the report to cancel rendering
    Dim returnValue As Boolean = False
    While Not returnValue
        returnValue = ReportViewer2.CancelRendering(millisecondsTimeout)
        Threading.Thread.Sleep(10)
    End While
End Sub

我认为如果问题只是偶尔出现,我可以继续尝试取消报告的呈现,直到它真正起作用。我想这是有效的,因为CancelRendering函数必须有可以和不能停止的点。当我看到报告在尝试进行尝试失败后仍保持渲染时,我想为什么不循环CancelRendering直到它起作用。