3
I have a timer
that I am testing and the same returns me an error:
An Exception of type 'System.Web.Httpexception' occurred in System.Web.dll but was not handled in user code
Additional information: Answer not available in this context.
private static System.Timers.Timer timer;
protected void btnGerarArquivo_Click(object sender, EventArgs e)
{
timer = new System.Timers.Timer();
timer.Interval = 60;
timer.Elapsed += new ElapsedEventHandler(Teste);
timer.Enabled = true;
}
public void Teste(object source, ElapsedEventArgs e)
{
try
{
Response.Write("teste");
timer.Enabled = false;
}
catch (Exception ex)
{
Response.Write("erro " + ex.Message);
}
}
After the adjustments was this way, it no longer updates the screen:
System.Threading.Timer tTime;
protected void btnGerarArquivo_Click(object sender, EventArgs e)
{
tTime = new System.Threading.Timer(new TimerCallback(Teste), null, 15000, 6000);
}
public void Teste(object sender)
{
horaCriacaoPagina.Text = "Hora atualizada : " + DateTime.Now.ToLongTimeString();
}
You have to have more details of the bug, young man. Probably Exception doesn’t just say that.
– Jéf Bueno
@jbueno, I have only the content presented, added a Try catch, see if help
– Harry
You need to get the contents of
InnerException
. Adding a Try-catch will only make things worse, instead of having the entire Exception it will only return the message of the first exception, this is terrible. By the way, why do you put your code aslang-html
? This is C#, the syntax highlighting is impaired if you use the comment withlang-html
.– Jéf Bueno
@jbueno, I added the image, I used lang-html, because for me it is more practical to adjust the code.
– Harry
Your project is Web?
– Marco Souza
yes, it’s web thanks for the help
– Harry
And you want to generate a file?
– Marco Souza
actually I want to call a procedure with a time interval, I did this example to try to figure out why of the error.
– Harry
I think it’s cool that you edit and take these Response.Write, it gets a little confusing
– Eduardo Moreira
I made an adjustment to the question, I am using System.Threading.Timer tTime; more does not update the result on the screen
– Harry