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

L

Luke Davis

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.
}


}



--
Luke Davis, MCSE: Security
DEM Networks - Senior Systems Architect
7225 N First, Suite 105
Fresno, CA 93720
Office: 1 (559) 439-1000
Fax: 1 (866) 640-2041
www.demnetworks.com
 
B

bruce barker

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)
 
L

Luke Davis

I've only been programming in .NET for 3 months, can you give me an example
line of a wait command?

Thanks

--
Luke Davis, MCSE: Security
DEM Networks - Senior Systems Architect
7225 N First, Suite 105
Fresno, CA 93720
Office: 1 (559) 439-1000
Fax: 1 (866) 640-2041
www.demnetworks.com
 
L

Lit

Do you have to use threads?

Lit

Luke Davis said:
I've only been programming in .NET for 3 months, can you give me an
example line of a wait command?

Thanks

--
Luke Davis, MCSE: Security
DEM Networks - Senior Systems Architect
7225 N First, Suite 105
Fresno, CA 93720
Office: 1 (559) 439-1000
Fax: 1 (866) 640-2041
www.demnetworks.com
 
B

bruce barker

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)
 
L

Luke Davis

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.
 
H

Harshal Pachpande

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
 
L

Luke Davis

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

--
Luke Davis, MCSE: Security
DEM Networks - Senior Systems Architect
7225 N First, Suite 105
Fresno, CA 93720
Office: 1 (559) 439-1000
Fax: 1 (866) 640-2041
www.demnetworks.com
 
L

Luke Davis

Awesome possom

Worked great



bruce barker said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

request.querystring 4

Members online

Forum statistics

Threads
474,262
Messages
2,571,050
Members
48,769
Latest member
Clifft

Latest Threads

Top