我刚开始学习C#,正在尝试编写一个测试网络连接的表单。我的想法是将连接部分放在线程中,在连接期间显示进度对话框。以下是我的代码:
Form_TestingConnection testingConnection = new Form_TestingConnection();
Thread t1 = new Thread(TestConnection);
try
{
testingConnection.ShowDialog();
t1.Start();
}
catch (Exception ex)
{
Logger.Error(ex);
if (MessageBox.Show(
Resources.message_connection_issue,
Resources.title_connection_issue,
MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
{
loginSuccessful = false;
}
}
TestConnection是一种测试连接并根据结果设置静态成员变量loginSuccessful的方法。我现在遇到的问题是代码卡在了testingConnection.ShowDialog()上。每当执行到这个地方时,它就不再前进了。有什么建议吗?非常感谢。