|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Property Feature For Comparing DateTimeI dont know whether I am doing this correctly or not. I want some procedure to fire when the time b/w the last and the current request is > 15 min I declared a global variable (txtPrev as string) and set it initially to datetime.now (tostring) and the clicked event of a button compare that datetime.now - prevtime.. but the global variable has nothing in it... why? I thought it would be set when declared globally for some reason its null (either my understanding is totally wrong or something is screwed up If newDateTime.Now.Subtract(DateTime.Parse(txtPrev)).TotalMinutes > 2 Then <-- error out here else end if I TRY THIS TOO... BUT DOES NOT WORK EITHER I have no understanding of Property but thought I would try... please do help me in understanding this Public Property X() As DateTime Get Return X End Get Set(ByVal Value As DateTime) X = Value End Set End Property Suppose during page load I do this t_PrevTime = X.Now and then while comparing at the clicked_event why does it take the value of #12.00 AM# If prevDateTime.Now.Subtract(X).TotalMinutes > 2 Then <--- thought it should set X to X.Now else Endif Please advice... I feel as if I am doing this in worst possible way, if there is a better way please do let me know. Thanks in Advance, Stephen here's an idea
in your Page_Load method, cache some object with a sliding expiration of 15 minutes. then, on subsequent loads of the page, simply access that cache item to keep it "fresh" so, something like this (i have not tested this code - caveat emptor): protected void Page_Load(object sender, EventArgs e) { System.Web.Caching.CacheItemRemovedCallback onRemoveCallback = new System.Web.Caching.CacheItemRemovedCallback(myCallbackHandler); if (!IsPostBack) { Cache.Add("x", "x", null, DateTime.MaxValue, new TimeSpan(0, 15, 0), System.Web.Caching.CacheItemPriority.Normal, onRemoveCallback); } else { // just access the cached item to keep it "alive" in the cache, and // therefore not provoke the firing of the onRemoveCallback string y = (string)Cache["x"]; } } public void myCallbackHandler(String k, Object v, CacheItemRemovedReason r) { // do your processing here for the case // where the page has not been accessed for the last 15 mins } Thanks Albert,
will work with the suggestion Thanks, stephen Show quoteHide quote "albert braun" <bcaguard2000-googlegro***@yahoo.com> wrote in message news:1134674547.130045.300080@o13g2000cwo.googlegroups.com... > here's an idea > > in your Page_Load method, cache some object with a sliding expiration > of 15 minutes. > > then, on subsequent loads of the page, simply access that cache item to > keep it "fresh" > > so, something like this (i have not tested this code - caveat emptor): > > protected void Page_Load(object sender, EventArgs e) > { > > > System.Web.Caching.CacheItemRemovedCallback onRemoveCallback = > new > System.Web.Caching.CacheItemRemovedCallback(myCallbackHandler); > > if (!IsPostBack) > { > Cache.Add("x", "x", null, DateTime.MaxValue, > new TimeSpan(0, 15, 0), > System.Web.Caching.CacheItemPriority.Normal, > onRemoveCallback); > } > else > { > // just access the cached item to keep it "alive" in the > cache, and > // therefore not provoke the firing of the onRemoveCallback > string y = (string)Cache["x"]; > } > > } > > public void myCallbackHandler(String k, Object v, > CacheItemRemovedReason r) > { > // do your processing here for the case > // where the page has not been accessed for the last 15 mins > } >
Other interesting topics
Anyone tried the design templates from MSDN?
Please help me with FxCOP 1.32 and ASP.NET 2.0 .Net 2, asp:Literal outside a server form = unrecognized tag prefix Poping up a window AND redirecting the page thtat triggered the po Auto Mode FTP in .NET 1.1 Gripe: usability problems with directory listing in .Net 2 Getting Value out of a data repeater checkbox download location... Virtual images for the team system RAM based cookies dataset question - to preserve DB resources |
|||||||||||||||||||||||