2017-03-17 41 views
0

我有一個Winforms應用程序,其中包含(除其他之外)Telerik DocumentTabStrip的主窗體。這些標籤用於保存用戶控件或網頁(通過網頁瀏覽器控件)。它工作得很好,但我現在遇到了一個問題。將文檔窗口添加到DocumentTabStrip會導致應用程序無限掛起

我最近將Web瀏覽器控件從基於IE的內置.NET Web瀏覽器切換到CefSharp。既然這樣做,我注意到偶爾在試圖將DocumentWindow添加到DocumentTabStrip時,調用將無限期地掛起(在調試中)或完全崩潰(通常運行應用程序)。只有當打開包含瀏覽器控件的DocumentWindow時,纔會出現,而不是其他任何用戶控件。實際的通話本身就在下面。

因爲沒有收到錯誤 - 它只是無限期地掛在Controls.Add()方法中,所以我對於如何開始調試這件事感到有點不知所措。任何意見,將不勝感激。

Private dts As New Telerik.WinControls.UI.Docking.DocumentTabStrip 


Try 


    dts.InvokeIfRequired(Sub() 
     Dim docWindow As Telerik.WinControls.UI.Docking.DocumentWindow = Nothing 
     Dim ctrl As ucBaseControl = Nothing 
     Dim browser As ucBrowser = Nothing 
     Dim isBrowser As Boolean = False 

     docWindow = New Telerik.WinControls.UI.Docking.DocumentWindow 
     docWindow.BackColor = Color.FromArgb(89, 89, 89) 

     'Do various stuff to determine the type of control to load (ctrl or browser), then setup the applicable control 

     If isBrowser Then 
      'Place the browser into the Document Window. 
      If Not IsNothing(browser) Then 
       browser.Dock = DockStyle.Fill 
       docWindow.Controls.Add(browser) 
      End If 
     Else 
      'Place the ctrl into the Document Window. 
      ctrl.Dock = DockStyle.Fill 
      docWindow.Controls.Add(ctrl) 
     End If 

     'Add the DocumentWindow to the DocumentTabStrip 
     ' Ensure DockWindow not disposed due to lag in bringing up 
     If IsNothing(docWindow) OrElse docWindow.IsDisposed Then 
      Exit Sub 
     End If 
     Try 
      docWindow.Padding = New Padding(0) 
      dts.TabStripElement.Children(0).Children(1).Padding = New Padding(0) 
      dts.Controls.Add(docWindow) 'This is where the issue is. It only happens sporadically here. 
     Catch ex As Exception 
      'Code to log any exceptions here. In the problem described here, no exception is ever generated, though. 
     End Try 

     'Bring the control to the front and focus it, here... 
    End Sub) 
Catch ex As Exception 
    'Error handling code here' 
End Try 
+0

被拋出任何異常痛苦

沒有異常被丟進?如果是這樣,請發佈堆棧跟蹤。 – TEK

+0

@TEK Nope,一點也不例外。在逐步完成時,它將進入Controls.Add方法並且永不返回。在Visual Studio之外,它添加了DocumentWindow並且沒有任何錯誤地崩潰。 – Locke

+0

你的'InvokeIfRequired'方法的邏輯是什麼?我假設這是你爲'Control'創建的擴展方法。請注意,如果它依賴'Invoke',這是一個同步調用,而是使用'BeginInvoke'(請參閱:http://stackoverflow.com/questions/229554/whats-the-difference-between-invoke-and-begininvoke/ 229558#229558)。另一個出發點可以是在調用'dts.Controls.Add(docWindow)''後調用'dts.CreateControl()'。請注意,這些只是一些調試步驟供您使用,因此是評論而不是答案。 – TEK

回答

相關問題