I have a page that has 3 used controls that are dynamically added to the page. One of these use controls hits a class that pulls a record set from the database (a rather quick request) and the other 2 user controls hit a single class and return a dataset from the database. The 2 that share a single class take an average of 10 seconds to return the data. Now what I want is for a user to hit the page and see 3 loading bars and have each user control load in the background. I want them all to start loading at the same time.
I have tried to call threading on the page containing the user controls like this:
protected void Page_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Load1));
t.Start();
t.IsBackground = true;
t.Priority = ThreadPriority.Highest;
t.Join();
Thread s = new Thread(new ThreadStart(Load2));
s.Start();
s.IsBackground = true;
s.Priority = ThreadPriority.Highest;
s.Join();
Thread r = new Thread(new ThreadStart(Load3));
r.Start();
r.IsBackground = true;
r.Priority = ThreadPriority.Highest;
r.Join();
}
private void Load1()
{
Control ctrl1 = LoadControl(@"\Controls\ctrl1.ascx");
Pnl1.Controls.Add(ctrlPreSolic);
}
private void Load2()
{
Control ctrl2 = LoadControl(@"\Controls\ctrl2.ascx");
Pnl2.Controls.Add(ctrlActive);
}
private void Load3()
{
Control ctrl3 = LoadControl(@"\Controls\ctrl3.ascx");
Pnl3.Controls.Add(ctrlNonActive);
}
however this is not working, it is always loading the first control, then the second, then the third in a line not all at the same time. Is this the wrong way to approach a web application? Can you thread a web application? I really need help with this if anyone can help me out!