我有一个带有pdf阅读器的winform控制AxAcroPdf阅读器,事情是在我将pdf文档检索到控件后,当我想关闭窗体时,大约需要30秒才能完成事件,我一直在寻找原因,事件将Dispose()事件放到控件中,但无法在适当的时间内关闭窗体,总是需要大约30秒才能关闭窗体...
这是我拥有控件的窗体中的代码...
Private Sub cargarPdf(ByRef nombre_Archivo)
Try
AxAcroPDF1.Visible = True
Dim con As SqlConnection = New SqlConnection(cadena)
Dim comando As SqlCommand = con.CreateCommand()
comando.CommandText = "SELECT file_stream FROM dbo.Tabla_archivos where name = @name"
comando.Parameters.AddWithValue("@name", nombre_Archivo)
con.Open()
Dim dr As SqlDataReader = comando.ExecuteReader(CommandBehavior.CloseConnection)
dr.Read()
Dim bufferSize As Integer = Convert.ToInt32(dr.GetBytes(0, 0, Nothing, 0, 0))
datos = New Byte(bufferSize - 1) {}
dr.GetBytes(0, 0, datos, 0, bufferSize)
dr.Close()
WriteBinaryFile("C:\Cobit\" + nombre_Archivo, datos)
AxAcroPDF1.src = "C:\Cobit\" + nombre_Archivo
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub这是基本表单中的代码...
Private Sub BtnCerrar_Click(sender As Object, e As EventArgs) Handles Button1.Click
If NombreLbl.Text = "Vista Archivos de evidencia" Then
Try
Frm_vista_archivos_evidencia.AxAcroPDF1.Dispose()
Catch ex As Exception
End Try
End If
Me.Close()
End Sub具有该控件的窗体是从Frm_base派生的窗体
发布于 2017-02-18 07:03:12
Acrobat Reader的最新版本中存在一个错误,该错误会导致控件在窗体关闭时出现延迟。在打开PDF文档的情况下,似乎有一些指向它的链接。可以通过将控件的src属性设置为不存在的PDF文件来强制该控件关闭文档;将其设置为Nothing或空字符串没有任何效果。这种文档关闭技术的功劳归功于Adobe论坛发布的How do I clear the file from AxAcroPDF object?中的"kenstanley2014“。如果先关闭文件,然后关闭窗体,它将很快关闭。然而,我发现这必须通过两个独立的UI交互,因为将它们放在相同的方法中会失败,就像设置src属性和使用计时器触发close命令一样。
不管出于什么原因,我决定看看隐藏表单是否会有效果。它做到了!,而且根本不需要设置src属性。只需在FormClosed事件处理程序中将窗体的Visible属性设置为False即可。
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
Me.Visible = False
End Sub我不知道为什么会这样,你的体验可能会有所不同。已在Windows 10 64位和Adobe Acrobat Reader DC版上进行测试。15.023.20056.16516。
https://stackoverflow.com/questions/42301320
复制相似问题