我有以下代碼修改每當用戶離開時可觀察的'屏幕'集合。WPF:從調度程序修改CollectionView仍然會拋出錯誤
void OnUserLeft(int roomId, int userId, string username)
{
client.ClientDispatcher.Invoke(
(Action<int>)((id) =>
{
Console.WriteLine("Hello before the storm!");
var screensToCheck = client.Screens.Where(s => s.CpuId == id).ToList();
screensToCheck.Each(s => client.Screens.Remove(s));
Console.WriteLine("Hello there!");
}), userId);
}
這是封裝在一個調用客戶端的調度程序,據說是通過與CollectionViews有關的線程問題。但是,我仍然會遇到以下例外情況:
此類CollectionView不支持從與分派器線程不同的線程更改其SourceCollection。
分派以上你看到的是在WPF應用程序的MainViewModel設置(我們使用MVVM),像這樣:
public Dispatcher ClientDispatcher
{
get { return Dispatcher.CurrentDispatcher; }
}
什麼是「客戶調度員」? – Jon 2010-05-13 21:48:25
對不起,在這個問題上添加了一些關於'ClientDispatcher'的信息。 – Dusda 2010-05-13 21:51:53