我是多线程的新手,我试图在线程结束时调用一个简单的警报按钮。这是我的代码...请让我知道这有什么问题,因为它不起作用。
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 */);
}
}