WPFアプリケーションに取り組んでいます。に「Status_label」というラベルがありMainWindow.xaml
ます。別のクラス(signIn.cs)からコンテンツを変更したいと思います。通常、私はこれを行うことができます
var mainWin = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;
mainWin.status_lable.Content = "Irantha signed in";
しかし、私の問題は、signIn.csクラスの別のスレッドを介してアクセスしようとすると、エラーが発生することです。
The calling thread cannot access this object because a different thread owns it.
Dispatcher.Invoke(new Action(() =>{..........
または何か他のものを使用してこれを解決できますか?
編集: 私はこのラベル変更アクションを別のクラスからも別のスレッドと呼ぶつもりです
MainWindow.xaml
<Label HorizontalAlignment="Left" Margin="14,312,0,0" Name="status_lable" Width="361"/>
SignIn.cs
internal void getStudentAttendence()
{
Thread captureFingerPrints = new Thread(startCapturing);
captureFingerPrints.Start();
}
void mySeparateThreadMethod()
{
var mainWin = Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;
mainWin.status_lable.Dispatcher.Invoke(new Action(()=> mainWin.status_lable.Content ="Irantha signed in"));
}
linevarmainWinリターンエラーThe calling thread cannot access this object because a different thread owns it.
案内してください、
ありがとうございました