我对使用 Dispatcher 有点困惑。我在 xap 中有 5 个网格,我正在尝试将每个网格与来自 WCF 服务的数据绑定
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(GetData));
//This is followed by getting data for other grids
}
private void GetData(object state)
{
Dispatcher.BeginInvoke(delegate()
{
WCFservice.ReadDataCompleted += new EventHandler<ReadDataCompletedEventArgs>(WCFservice_GetData);
WCFservice.ReadDataAsync();
});
}
void WCFservice_GetData(object sender, ReadDataCompletedEventArgs e)
{
//is this correct
myGrid.ItemsSource = myCollection;
//OR should I use dispatcher here as well when I bind to the grid
Deployment.Current.Dispatcher.BeginInvoke(() => { myGrid.ItemsSource = myCollection; });
}