Silverlight 4 ベータ版を使用して 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)」