"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