我正在开发一款软件中的一些代码存在问题。
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的匿名方法中返回值”。
答案 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);