ASP.NET Threading (It's not showing up!)

  • Thread starter Thread starter LD
  • Start date Start date
L

LD

When I run this codebehind on page load, none of the labels update, and I
don't get any errors. See if you can figure it out:


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Thread RETSThread = new Thread(RETSProcess);
RETSThread.Start();

Thread RSSThread = new Thread(RSSProcess);
RSSThread.Start();
}


void RETSProcess()
{
//Retrieves info from a proprietary Real Estate DB and updates
labels with appropriate information, this also does not work, all of the
labels are left blank
}

void RSSProcess()
{
//Retreives RSS information and populates a table on the page,
that doesn't come up at all now.
}


}
 
you need to add a wait (say at prerender or last statement in onload)
for the threads to complete. otherwise the rendered html is sent to the
browser before they complete, and changing the labels has no impact.

-- bruce (sqlwork.com)

> When I run this codebehind on page load, none of the labels update, and I
> don't get any errors. See if you can figure it out:

> public partial class _Default : System.Web.UI.Page
> protected void Page_Load(object sender, EventArgs e)
> Thread RETSThread = new Thread(RETSProcess);
> Thread RSSThread = new Thread(RSSProcess);
> RSSThread.Start();

> void RETSProcess()
> //Retrieves info from a proprietary Real Estate DB and updates
> labels with appropriate information, this also does not work, all of the
> labels are left blank
> void RSSProcess()
 
I've only been programming in .NET for 3 months, can you give me an example
line of a wait command?

Thanks
> you need to add a wait (say at prerender or last statement in onload) for
 
protected void Page_Load(object sender, EventArgs e)
{
Thread RETSThread = new Thread(RETSProcess);
RETSThread.Start();

Thread RSSThread = new Thread(RSSProcess);
RSSThread.Start();

// wait for threads

RETSThread.Join();
RSSThread.Join();

}


-- bruce (sqlwork.com)


> I've only been programming in .NET for 3 months, can you give me an example
 
Right now it takes a long time to display the text and I am looking for a
way to cut back on the time, and I'm hoping that starting two threads might
help. They are both web services that I am referencing, instead of waiting
for the RETS connection to complete before starting the RSS connection, I'll
start them at the same time.
 
protected void Page_Load(object sender, EventArgs e)
{
Thread a = new Thread(A);
a.Start();


Thread b = new Thread(B);
b.Start();
}

private void A()
{
this.l1.Text = "l1 text";
}

private void B()
{
this.l2.Text = "l2 text";
}

Above worked for me with ASP.NET 2.0
Can data retrieval be a problem?

- Harshal
 
That's because processing those are quick, calling for information from a
remote server takes a while.


> protected void Page_Load(object sender, EventArgs e)
> Thread a = new Thread(A);

> Thread b = new Thread(B);
> b.Start();
> private void A()
> this.l1.Text = "l1 text";
> private void B()
> this.l2.Text = "l2 text";
> Above worked for me with ASP.NET 2.0
 
Back
Top