Are timers safe for asp.net apps?

J

jensen bredal

Hello,

I need a timer functionality in my asp.net app. I have dropped the
timer component available on the toolbox of the IDE on global.asax.cx
designer page view and dubble clicked to include the code and event for it .

My first attempt to run the code resulted in aspnet_wp.exe hanging with a
huge amount of memory.

How do i best accomplish this(use the timer)?


many thanks

JB
 
P

Patrice

What do you want to do ?

Do you need a timer server side or client side ?

Patrice
 
S

Scott Allen

It sounds like you are using a System.Timers Timer, which is ok to use
server side, although there are some gotchas.

What does yoru code do? The timer itself should not cause hangs and
memory problems.
 
J

jensen bredal

I need to update my application data in cache.

Will this actually be multithreaded or will it cause requests to wait for my
update?
 
P

Patrice

I saw in the other thread that is to update a cache ? What are you using to
handle this cache ?

The "cache" class already has an expiration mecanism. You'll have just to
reload the data if they are missing (you can even have a callback the entry
is cleaned up)... IMO you don't need a timer for this...

Other than that it's likely you have something that is not cleaned up
properly...

Patrice
 
J

jensen bredal

Well i need to update a cahce.
Right. So i could define a callback function that is called. I was not aware
that the cache had this capability.
Thanks
 
S

Scott Allen

Thats a good suggestion Patrice. There is a callback event you can
hook when the cache item expires, and during the event processing
Jensen could update the cache entry.
 
B

Brock Allen

I need to update my application data in cache.

Why do this in a timer? Why don't you let the Cache do its own timeout (you
can set the interval when calling Insert) and then just lazy load the data
the next time you need it? It's much simpler than doing a timer yourself.
 
B

Brock Allen

Thats a good suggestion Patrice. There is a callback event you can
hook when the cache item expires, and during the event processing
Jensen could update the cache entry.

But again, why do it this way? It's usually much easier to just lazy load
the data upon the next request for it if the Cache has timed out. *shrug*
 
P

Patrice

Yes I mentioned the callback stuff but actually my personal preference would
be to lazy load the data...

The only thing I could think of would be those that are annoyed because they
are loading a fair amout of data taking then a hit. Generally they don't
want to delay the load so that the one who needs first the data doesn't
incur this hit (but IMO it has its own drawback such as what you do if there
is no data yet, even though I would likely try to see if all those data
wouldn't belong actually to distinct smaller caches)...

Patrice

--
 
E

Eliyahu Goldin

You better tell us what are you going to achieve. You might be on a wrong
track altogether.

Eliyahu
 
P

Patrice

It just means that you load the data when they are first needed :

- check the cache
- if not in cache load and cache your data
- use them

Of course you could wrap this inside a method so that your app just call the
same method whithout having to deal with these low level details each
time...

Patrice
 
B

Brock Allen

DataSet ds = Cache["MyDataSet"] as DataSet;
if (ds == null)
{
ds = new DataSet();
/// Load ds from DB
Cache.Insert("MyDataSet", ds, .... );
}

In essence, look to see if it's in the cache, if it's not then get the data
and refresh the cache. This snippet is a bit oversimplified, as there's a
subtle timing issue here, but for the most part it'll work for you.
 
J

jensen bredal

The delegate way sounds more interesting to me though. There there more
chance that my
the data get relaoded when there no request .

I'm right?
 
J

jensen bredal

well that is thev problem.

Load DB in my case can take quiet some time , resulting in bad user
experience.
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top