Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Remove Things in Application State After Period?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lucius - 25 Jun 2007 18:57 GMT
I would like to remove things from Application state if they are older
than 15 minutes. How can I do that?

Thanks.
Peter Bromberg [C# MVP] - 25 Jun 2007 20:37 GMT
Depends how you stored them in Application State. There is nothing to stop
you from creating a little "container" class that has an object field to hold
your "thing" and a DateTime field to hold the time you stored it.

Peter
Signature

Site:  http://www.eggheadcafe.com
UnBlog:  http://petesbloggerama.blogspot.com
Short urls & more:    http://ittyurl.net

> I would like to remove things from Application state if they are older
> than 15 minutes. How can I do that?
>
> Thanks.
Steven Cheng[MSFT] - 26 Jun 2007 08:37 GMT
Hi Lucius,

For your scenario, you want to store some shared objects in the global
Application State collecction and make it be cleared after a certain
period. I think you'd better consider using the Application Cache instead
of ApplicaitonState.  The Application Cache is also a global storage of
ASP.NET application and you can store and access items into it like a
dictionary. Also, you can supply a CacheDependency for each cache item so
as to control how will the cached item expired(be removed from cache
collection). e.g.

//cache and object and supply the lifetime(to expire)
Cache.Insert("item key", objectToCache, null, DateTime.MaxValue,
TimeSpan.FromSeconds(10));

#Cache.Insert Method (String, Object, CacheDependency, DateTime, TimeSpan)
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx

Actually, the ApplicationState is provided for backward compatibility to
original classic ASP. You can use Application Cache to replace
ApplicationState in ASP.NET application.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Steven Cheng[MSFT] - 28 Jun 2007 16:26 GMT
Hi Lucius,

Does the cache approach mentioned in last reply address the problem? If you
have any further questions, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
   

This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.