您好,
我女巫一个LogInWindow.xaml.cs,我创建一个本地方法的线程,在巫婆,我试图调用一个方法从外部类Client.connect的(字符串1,字符串),我得到下面的异常:{BR }
{调用线程不能访问此对象,因为不同的线程拥有它的System.InvalidOperationException:
60; 在System.Windows.Threading.Dispatcher.VerifyAccess()
在System.Windows.DependencyObject.GetValue(DependencyProperty的DP)
System.Windows.Controls.TextBox.get_Text()
在C:\用户\盖比\ \ Visual Studio 2010的\项目\扑克\扑克\ LogInWindow.xaml.cs Poker.LogInWindow.callLogIn():第86行}
我应该怎么办?谢谢!
的问候,
SAS加布里埃尔
代码:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (userInput.Text == "")
MessageBox.Show("Please enter your username.");
else
if (passInput.Password == "")
{
MessageBox.Show("Please enter your password.");
}
else
{
button1.IsEnabled = false;
Thread t = new Thread(new ThreadStart(callLogIn));
t.Start();
}
}
public void callLogIn()
{
try
{
Client.connect(userInput.Text, passInput.Password);//this is where i am getting the exception
}
catch (Exception e)
{
LogInWindow.btn.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
LogInWindow.btn.IsEnabled = true;
}
));
MessageBox.Show("Could not connect to server. Please try again later. ");
}
}