Dispatcher.BeginInvoke C#中的代码路径错误

时间:2011-02-05 13:09:24

标签: c# wpf

我正在开发一款软件中的一些代码存在问题。

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 个答案:

答案 0 :(得分: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);