我一直在試圖弄清楚這個問題。談到線程時我很困惑。動態更新UI時執行線程
我想要做的是在函數中有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
}
}
}
我在哪裏放置了意見就是我想要的線程暫停和繼續...
任何人有任何輸入?
感謝
http://www.google.com/search?q=update%20ui%20background%20thread –