How to pass an <asp:Label to a thread

X

xzzy

I need to update the .Text of a label until the user logs out.

but get this error:

Error: Method name expected

I have listed the code below and the offending line of code is delimited by

//The next line breaks: Error: Method name expected


Thank you,

John Bickmore



++++++++++++++++++++++++++++++++++++++++
In code behind of footer.aspx

A. Parameters:
1. ctlLabel is an <asp:Label
2. SessionStartTime is the System.DateTime.Now of when the viewer
logged in

B. In Footer.aspx.cs, the thread is created with:

fFooter myFooter = new fFooter();
myFooter.Update(ctlLabel,SessionStartTime);



++++++++++++++++++++++++++++++++++++++++
using System;
using System.Threading;

namespace fFooter
{
/// <summary>
/// Summary Called from Footer.aspx.cs to update the footer with
/// Summary the time in minutes the viewer has been logged in.
/// </summary>
public class fFooter
{
public Thread myThread;

//Parameter(s)
System.DateTime xSessionStartTime;

public void Update(System.Web.UI.WebControls.Label yLabel, System.DateTime
ySessionStartTime)
{
xSessionStartTime = ySessionStartTime;


//The next line breaks: Error: Method name expected

myThread=new Thread(new ThreadStart(UpdateLabel(yLabel)));

//The line above breaks: Error: Method name expected



myThread.Start();
}

private void UpdateLabel(System.Web.UI.WebControls.Label yLabel)
{
while ( true )
{
yLabel.Text = tTime(xSessionStartTime);
Thread.Sleep(1000);
}
}

private string tTime(System.DateTime xSessionStartTime)
{
string xx = "Active for: ";
System.DateTime dtBdate = xSessionStartTime;
System.DateTime dtToday = System.DateTime.Now;
System.TimeSpan tsTotal = dtBdate - dtToday;
decimal xDECIMAL = Convert.ToDecimal(tsTotal.TotalMinutes * -1);
int xINT = Convert.ToInt32(decimal.Round(xDECIMAL,0));

if (xINT < 1 )
{
return "Just logged in";
}
else
{
if (xINT == 1)
{
return xx + "1 minute";
}
else
{
return xx + xINT + " minutes";
}
}
}//end of method: tTime
}//end of class: Footer
}//end of Namespace: clsFooter
 
B

Brock Allen

ThreadStart takes a delegate to a method with no params and no return (and
in 2.0 there's another version that accepts an object parameter). But I have
a feeling that even if you got the delegate right, it's still not going to
do what you want. If you spin up another thread, the first thread will continue
processing and render the result back to the browser. Your secondary thread
will kick in at some point and try to update a control on the page that probabaly
has already been rendered out to the client. In short, I think you're going
to have problems. What exactly are you trying to do?

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
X

xzzy

I need to do something to fire:

Application_PreRequestHandlerExecute

without the viewer having to do anything.

John
 

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

Top