我是新的多線程,我試圖在線程結束時調用簡單的警報按鈕。這是我的代碼...請讓我知道這是什麼問題,因爲它不工作。在線程結束時向ASP.NET發送消息
public static void RunUpload()
{
Thread thread = new Thread(RunUploadOnThread);
thread.Start();
while(thread.IsAlive)
{
Show("Rate upload in progress.");
}
Show("Rate upload completed.");
}
Show()
只是把網頁上的信息:
public static void Show(string message)
{
string cleanMessage = message.Replace("'", "\'");
Page page = HttpContext.Current.CurrentHandler as Page;
string script = string.Format("alert('{0}');", cleanMessage);
if (page != null &&
!page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(
page.GetType(), "alert", script, true /* addScriptTags */);
}
}
你得到了什麼錯誤? – Vandesh
'thread.Join();'會等到線程結束(但也阻止你的UI :))。 – I4V
我沒有收到任何錯誤,我想要的只是在alert中顯示消息。 – user2123852