我正在尝试遵循使用 Silverlight 4 beta 执行 WCF 数据服务查询的模式。以下是我的代码:
public CodeTables()
{
CodeCountries = new ObservableCollection<dsRealHomes.CodeCountries>();
dsRealHomes.RealHomesEntities myClient = null;
myClient = staticGlobals.RealHomesContext();
object userState = null;
myClient.BeginExecute<dsRealHomes.CodeCountries>(new Uri("CodeCountries"),
(IAsyncResult asyncResult) =>
{
Dispatcher.BeginInvoke(
() =>
{
var test = myClient.EndExecute<dsRealHomes.CodeCountries>asyncResult).ToList();
}
);
}, userState);
}
这是从我遇到的使用 silverlight 的 WCF 数据服务的一些示例中得出的。不幸的是,无论我如何尝试实现代码,我都会在“Dispatcher.BeginInvoke”上遇到以下错误:
'非静态字段、方法或属性需要对象引用 (System.Windows.Threading.Dispatcher.BeginInvoke(System.Action)'