我一直在努力解决这个问题。当谈到线程时,我很困惑。
我正在尝试做的是在函数中延迟 1 次暂停并继续该函数,直到另一个 1 秒的暂停出现并最终完成该函数。
public partial class SplashScreen : Form
{
public SplashScreen()
{
InitializeComponent(); // initalize splash screen
DatabaseStatus(); // set database connection
getUserInfo(); // get user information
showInfo(); // show app information on splash screen
System.Threading.Thread wa = new System.Threading.Thread(new System.Threading.ThreadStart(checkUser));
wa.IsBackground = true;
wa.Start();
}
void checkUser()
{
if (RegisteredUser)
{
richTextBox1.Text += "Loading user settings..."; // SHOW THIS TEXT AND WAIT 1 SECOND UNTIL NEXT
System.Threading.Thread.Sleep(1000);
if (DATABASE_CONNECTION)
{
richTextBox1.Text += "Loging on...";
// WAIT AGAIN 1 SEC AND CONTINUE///
LoginCheck login = new LoginCheck(USER_NAME, PASSWORD);
if (login.LOGIN_SUCESS)
{
richTextBox1.Text += "Sucess!";
// SHOW THIS TEXT AND WAIT 1 SEC UNTIL SPLASH SCREEN FADE OUT//
//MessageBox.Show(login.HASH);
opac.Interval = 12;
opac.Start();
opac.Tick += new EventHandler(dec);
}
else
{
MessageBox.Show(login.HASH);
}
}
}
else
{
richTextBox1.Text += "Not user profile found...";
// ask user to register
}
}
}
我放置评论的地方是我希望线程暂停并继续的地方......
有人有意见吗?
谢谢