2017-02-13 104 views
0

当在Web浏览器中打开一个包含PDF文档的包含WebBrowser控件的表单时,表单需要大约10秒才能关闭。我将问题追踪到webbrowser的Dispose方法。c#web浏览器查看器控件需要时间处理

private void advBandedGridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) 
    { 
     if (advBandedGridView1.GetFocusedDataRow() != null) 
     { 
      string wordno = advBandedGridView1.GetFocusedDataRow()["wordno"].ToString(); 
      string itemcd = advBandedGridView1.GetFocusedDataRow()["itemcd"].ToString(); 

      for (int i = 0; i < _caseCount; i++) 
      { 
       ButtonColoring(wordno, _seqkindCode[i]); 
      } 

      LoadPDF(itemcd); 

      gridControl2.DataSource = null; 
      gridControl2.RefreshDataSource(); 
     } 
    } 

控制事件

private void LoadPDF(string itemcd) 
    { 
     try 
     { 
      ReturnPacket rp; 

      rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = 'EYE'", false); 

      if (rp.DataTables.Count > 0 && rp.DataTables[0].Rows.Count == 0) 
      { 
       rp = new Q3i.POP.BIZ.Common.CommonCode().SelectCommonCodeFull("603", "kind3 = '1'", false); 
      } 

      if (rp.DataTables[0].Rows.Count > 0) 
      { 
       string dockind = string.Empty; 
       dockind = rp.DataTables[0].Rows[0]["code"].ToString(); 

       ParameterCollection paramCol = new ParameterCollection(); 
       paramCol.Add("p_itemcd", itemcd); 
       paramCol.Add("p_dockind", dockind); 
       PdfFileInfo temp_fileInfo = biz.SelectInspectionStandards(paramCol); 

       if (temp_fileInfo != null) 
       { 
        if (_fileInfo != null && temp_fileInfo.FileNm == _fileInfo.FileNm) 
        { 
         WebBrowserPdf.Visible = true; 
         return; 
        } 

        _fileInfo = null; 
        _fileInfo = temp_fileInfo; 

        PDF_FILE_PATH = FilePath + _fileInfo.FileNm; 

        DirectoryInfo di = new DirectoryInfo(FilePath); 
        if (di.Exists == false) 
        { 
         di.Create(); 
        } 

        if (!File.Exists(PDF_FILE_PATH)) 
         File.WriteAllBytes(PDF_FILE_PATH, _fileInfo.FileData); 

        if (!PDF_FILES.Contains(PDF_FILE_PATH)) 
        { 
         PDF_FILES.Add(PDF_FILE_PATH); 
        } 

        WebBrowserPdf.Navigate(PDF_FILE_PATH + "?#zoom=" + _zoomFactor + "%", false); 

        WebBrowserPdf.Visible = true; 
        simpleButtonOpenPOPUP.Enabled = true;       
       } 
       else 
       { 
        WebBrowserPdf.Visible = false; 
        simpleButtonOpenPOPUP.Enabled = false; 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Alert, true); 
     } 
    } 

它是Load方法

private void w_pcmu081_FormClosing(object sender, FormClosingEventArgs e) 
    { 
     try 
     { 
      WebBrowserPdf.Dispose(); 

      Process[] Pro = Process.GetProcessesByName("osk"); 
      if (Pro.GetLength(0) > 0) 
       Pro[0].Kill(); 
     } 
     catch(Exception ex) 
     { 
      UCXtraMsgBox.ShowDialog(ex.Message, "m0146", Q3i.Common.Enums.MsgBoxButton.OK, Q3i.Common.Enums.MsgBoxIcon.Info, true, null, true); 
     } 
    } 

关闭

+0

您是否尝试过处置'WebBrowser1'? –

+0

我试过两种方法。 WebBrowser.Dispose(true)和Form Close() –

+0

将'WebBroswer.Dispose'放入Form1_FormClosing'事件处理程序中。 –

回答

0

同样的情况也发生在我身上。
Adob​​e在最新版本的Acrobat Reader DC(15.023.20056)中做了一些错误。

如果您在编辑 - >首选项 - >安全性(增强)中取消选中选项启动保护模式启动,一切都将恢复正常。

在我的情况下,这不是一个解决方案。

此处了解详情:https://forums.adobe.com/thread/2267688