469,957 Members | 2,705 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,957 developers. It's quick & easy.

timers in WebServices

Hi, can timers be used in webservices?

as an example: to check at some time interval an object -
Application["LoggedUsers"] and for each logged user, check its login
period, and if it is greater than 30 minutes, remove it form the
collection.

Thank you,
Daniel
Nov 21 '05 #1
1 1712

"Bamse" <bd**************@yahoo.com> wrote in message
news:OF**************@TK2MSFTNGP09.phx.gbl...
Hi, can timers be used in webservices?

as an example: to check at some time interval an object -
Application["LoggedUsers"] and for each logged user, check its login
period, and if it is greater than 30 minutes, remove it form the
collection.

Thank you,
Daniel


There are a number of potential issues with using timers from within a Web
Service.

First off, don't use System.Timers.Timer. This is because
System.Timers.Timer uses the .NET threadpool which is also used by ASP.NET
to service web requests. With load, there's a chance that the
System.Timers.Timer fails to fire because there is no thread available. If
you must use a timer, use System.Threading.Timer instead. See
http://weblogs.asp.net/sibrahim/arch.../13/58429.aspx.

Another issue is that when your timer fires, you do not have access to the
HttpContext and other similar objects that are created by the ASP.NET
infrastructure for you when a web request comes in. Accessing the
Application object from within a timer callback might or might not work (I
haven't tried).

A more robust approach would be to use e.g., a separate Windows service to
call a Web Method periodically.

Regards,
Sami
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by GDumencu | last post: by
reply views Thread by Dmitry Demchuk | last post: by
reply views Thread by Cider123 | last post: by
3 posts views Thread by Nathan Kovac | last post: by
9 posts views Thread by Mark Rae | last post: by
5 posts views Thread by Michael C# | last post: by
8 posts views Thread by Komandur Kannan | last post: by
1 post views Thread by Jonathan Woods | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.