我有麻煩了。在我的web應用程序,我有創建一個按鈕的Click事件線程來執行數據密集型任務的代碼中,是這樣的:C#Web應用程序線程
protected void button_Click(object sender, EventArgs e)
{
// Show loader image
loader.Show();
// Creating the thread
System.Threading.ParameterizedThreadStart ts = new System.Threading.ParameterizedThreadStart(RunThread);
Thread t = new Thread(ts);
t.Name = "BackgroundThread";
t.Priority = ThreadPriority.AboveNormal;
t.Start(HttpContext.Current);
}
private void RunThread(object state)
{
// Setting the current thread property as the background thread
CurrentThread = Thread.CurrentThread;
if (IsThreadRunning(CurrentThread))
{
CurrentThread.Join(TimeSpan.FromMinutes(6d));
}
// DO SOME HEAVY STUFF
}
在點擊該按鈕i顯示了裝載機。問題是:即使呼叫加入在BackgroundThread,Page_Load事件被頻繁調用,使頁面刷新。換句話說,雖然RunThread沒有完成,Page_Load正在調用。我可以防止這種情況發生嗎?
OBS:我想要做的是:在數據密集型線程運行時顯示加載器,而不在頁面上進行重複刷新。
不要調用'page_load'的高優先級線程嗎?如果你解釋這個試圖解決什麼問題,也許可以提供一個更好的選擇。 – Oded
請讓你的問題更清楚,你想做什麼? – Anri
你爲什麼要在當前線程上調用'Join'?這是一個毫無意義的操作。 –