Property Feature For Comparing DateTime

S

Stephen

Hi,

I 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
 
A

albert braun

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
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top