我有麻烦了。在我的网络应用程序中,我有一个代码在按钮的 Click 事件上创建一个线程以执行数据密集型任务,如下所示:
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
}
在按钮中单击我显示加载程序。问题是:即使在BackgroundThread中调用Join, Page_Load 事件也会被频繁调用,从而使页面刷新。换句话说,当RunThread没有完成时, Page_Load 被调用了。我可以防止这种情况发生吗?
OBS:我想做的是:在数据密集型线程运行时显示加载器,而不需要在页面上进行重复刷新。