Reputation: 99
I have an Asp.Net application. For performance reason, some data is stored in Application State, like Application["MyData"] = myData; Can I configure it to make the data get cleared regularly?
Thanks.
Upvotes: 1
Views: 1577
Reputation: 877
Yes you can do it explicitly , two ways
Application state is in IIS in the worker process application pool. timeout settings here would do it
otherwise in c#
ApplicationPool.ProcessModel.PeriodicRestart.Time = TimeSpan.FromMinutes(5);
//or based on idle. just play around with ApplicationPool. items
ApplicationPool.ProcessModel.IdleTimeout = 600000;
Upvotes: 0
Reputation: 1183
They are just like variables, hence the name Application Variables. You can just reassign them to a new value.
Application["MyData"] = myData;
///Do something.
...
..
.
Application["MyData"] = myNewData;
Edit:
Application variables are specifically designed to last the lifetime of the application and not expire until the application closes. What you can do is assign every user a session variable who accesses your application and make it expire when you want.
Upvotes: 1