Timer control in webapplication

V

Varangian

Hi there,

I'm having problems using the Timer i.e. System.Timers.Timer (not the
one found on the toolbox) in a webapplication and its giving me
problems. Although I'm setting the interval to 5 secs (5000millisecs)
it seems that this interval is not being followed correctly. I'm using
Elapsed event to make something and this event is being raised
bizarrely after 2 secs, or after 3, sometimes after 5, sometimes less
than 1 sec :S or 2 in a row. I don't know, maybe doing something
incorrectly.

I tested this timer in WindowApplication, maybe because the Timer
doesn't work correctly on web. However it still does the same, i.e.
raising the event not following the correct interval. Below I have a
sample code of the timer in WindowsApplication but with no success at
all.

Any help appreciated thanks :)

private void button1_Click(object sender, System.EventArgs e)
{
System.Timers.Timer test = new System.Timers.Timer();

test.Interval = 5000;
test.Enabled = true;

test.Elapsed +=new System.Timers.ElapsedEventHandler(test_Elapsed);
}

private void test_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
MessageBox.Show ("SHOW");
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Where are you setting the timer?

Also, why are you using a timer in a web app?
 
V

Varangian

Hello Ignacio Machin, pondering about my situation I don't think the
timer has any used. Thanks for the reply anyway :). I may use the
Threading.Sleep :)
 
W

Willy Denoyette [MVP]

Varangian said:
Hello Ignacio Machin, pondering about my situation I don't think the
timer has any used. Thanks for the reply anyway :). I may use the
Threading.Sleep :)

And why would you put a webrequest to sleep?

Willy.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Varangian said:
Hello Ignacio Machin, pondering about my situation I don't think the
timer has any used. Thanks for the reply anyway :). I may use the
Threading.Sleep :)

Even worse !, you will get a timeout in the browser, IIS is configured to
not allow a request to run more than a given amount of time, otherwise a bad
programmed pages can take down the entire service.

What is what you want to do? that is what you have to explain in the first
place.
 

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