Shared BO by Static property and ServerDataChanged


Author
Message
ChanKK
ChanKK
StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)
Group: Forum Members
Posts: 190, Visits: 1.3K
Hi,

I would like to use static property to stored some shared BO instance and data (as suggested by SF). Beside, I also would like to implement "auto requery" if any underlying data changed at server.



Anyway to make sure "auto requery" doesn't crash the web app? e.g. while ServerDataChanged event fired, there might be record populating taking place for ASPX. It I try to re-fill at that time, it might crash the system. I was thinking to use lock() statement to lock another static object for this purpose. But where should I do so?



Please advice. Thank you
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
This can become a relatively complex converstation for an "auto-requery."  If you are using SQL Server, then you can use Query Notification Services to have events raised when the server data changes....however, this needs to be used with caution as there are some shortcomings that can cause a number of issues.

Let me share a suggestion with you that we have used in the past which works very well.  We use a row version field for all of our concurrency checking.  So every table in our databases will have an integer field that is used as a Row Version column.  The help docs will show how to setup the BO settings for this.

Once this is done, it makes if very easy to perform a simple scalar query to basically perform a checksum or a SUM comparison between the data that you have on your server and what is in your BOs.

For example, I may have a query that looks like this to retrieve all of my records:

SELECT * FROM MyTable

So I now want to setup a threaded timer to callback periodically to see if anything has changed:

private System.Threading.Timer queryTimer = new System.Threading.Timer(new System.Threading.TimerCallback(QueryCacheUpdate),
                                                                       null,
                                                                       new TimeSpan(0,1,0),
                                                                       new TimeSpan(0,1,0));

private static void QueryCacheUpdate(object state)
{
    //-- Establish Locals
    long checkSum = MyBo.GetRowVersionSum();
    long localSum = 0;

    //-- Compare the checkSum with the version SUM within the current BO.
    localSum = MyBO.CurrentDataTable.Compute(...);

    if(checkSum != localSum)
    {
        //-- Reload your cache here
    }
}

This should at least give you an idea of how to set something like this up.  Hope it helps. Smile

ChanKK
ChanKK
StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)
Group: Forum Members
Posts: 190, Visits: 1.3K
Hi,

Thank you for sharing.

However, I still interested to know, how to prevent crash when I reload my cache.

As ASP.NET is multi threading, and as the sample posted using timer to reload cache. What will happen when ASPX is using the cache data, at the same time the timer fired and cache reload? As sometime we might not able to use lock() statement to handle this. For example, I bind my cache to GridView, GridView is populating row in ASPX, at the same timer triggered reload cache code executed.



Please advice



Thank you
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Just create a static object on which to Lock when you call these methods.  If you have a static object that you Lock, it will resolve the synchronization locking issues.
ChanKK
ChanKK
StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)StrataFrame User (248 reputation)
Group: Forum Members
Posts: 190, Visits: 1.3K
Hi,

But GirdView row population is only happen may be in Page.DataBind() or Page.Render(). Do you meant I need to override them?
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Without me spending the time to totally flesh this out I cannot give you exacts. But it is logical that you may have to unbind and rebind when a refresh of the cache is executed.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search