問題は単純です。GUIc#/ xamlアプリがあり、あるスレッドでGUIを実行し、別のスレッドでいくつかのメソッド(無限ループ)を実行したいと考えています。そして、2番目のスレッドからGUI(リストボックス)の要素を変更する必要があります。Webからグローバル変数やその他のヒントを作成しようとしましたが、うまく機能しません。
今私は次のようなものを持っています:
public delegate void InvokeDelegate(listdata Mujlist);
//in global scope
// and in Window class
public void UpdateList(listdata Mujlist)
{
mujlistbox.DataContext = Mujlist;
}
// and in the second thread this
object[] obj = new object[1];
obj[0] = Mujlist;
mujlistbox.BeginInvoke(new InvokeDelegate(UpdateList), obj);
これはおそらくうまくいくかもしれませんが、VS 2010がエラーを見つけたため、これを試すことはできません
Error 1 'System.Windows.Controls.ListBox' does not contain a definition for 'BeginInvoke' and no extension method 'BeginInvoke' accepting a first argument of type 'System.Windows.Controls.ListBox' could be found (are you missing a using directive or an assembly reference?) D:\..\MainWindows.xaml.cs 85 28 WPFChat
しかし、 System.Windows.Formsにはこのメソッドがあるので、私はこれと混同しています。
だから、質問はどうすれば子スレッドから「GUIスレッド」のリストボックスを簡単に更新できますか?
どこを間違えますか?これを行うためのより良い方法はありますか?どのように?