Home All Groups Group Topic Archive Search About

Property Feature For Comparing DateTime

Author
15 Dec 2005 6:45 PM
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

Author
15 Dec 2005 7:22 PM
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
    }
Are all your drivers up to date? click for free checkup

Author
15 Dec 2005 7:57 PM
Stephen
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
>     }
>

Bookmark and Share