2011-02-05 56 views
0

我在一段我正在開發的軟件中存在一點代碼問題。Dispatcher.BeginInvoke C#中的代碼路徑錯誤#

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(delegate 
{ 
    AccountSyncOptions getData = new AccountSyncOptions(syncProgress, lblStatus, tblLogins, cboFilter, searching, searchString, btnClearSearch); 
    getData.retrieveLocalData(); 
    getData.retrieveOnlineData(); 
}), null); 

當我把上面的代碼中出現一個錯誤,其說System.Windows.Threading.DispatcherOperationCallBack「並非所有的代碼路徑在類型的匿名方法返回一個值」。

回答

1

DispatcherOperationCallback委託的簽名是

public delegate Object DispatcherOperationCallback(
    Object arg 
) 

所以,你需要從你的匿名方法返回一個對象:

this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(delegate 
{ 
    AccountSyncOptions getData = new AccountSyncOptions(syncProgress, lblStatus, tblLogins, cboFilter, searching, searchString, btnClearSearch); 
    getData.retrieveLocalData(); 
    getData.retrieveOnlineData(); 
    return null; 
}), null); 
+0

感謝您的幫助 – Boardy 2011-02-05 18:43:21