akshay
4/6/2006 7:18:00 PM
I facing a Static Member become Null on second call every now and then. -
I have one dataset made as Static Member. [_dsCacheHolder]
Each call to a function only returns a COPY Dataset.Copy() of the static
variable.
[public static PA_PropertyStructure GetCacheStructure()]
GetCacheStructure checks if Static member is null if yes then fills it up.
and returns a copy of the DS.
However I am observing a strange thing happening every now and then. As below:
1st time I call GetCacheStructure() - It loads up the static variable
dsCacheHolder and works fine.
Call again to GetCacheStructure() does this:
Finds _dsCacheHolder to be NULL.
Loads up _dsCacheHolder and as soon as it tries to return a copy of
_dsCacheHolder it finds that the variable is still NULL.
This code works fine almost 95% of the times - however on some days when
load to the server is low - it starts failing...
Also note i can re-create this issue / it was observed only on Windows 2003
and XP workstations. NT2000 servers works great, never seen any issue with
them.
Please help I m pulling my hair to get it fixed.
Code:
Tracer.TraceEnter();
savePoints = "entered try | ";
if (isCacheNotValid())
{
savePoints += "entered Cache Invalid 1 | ";
lock(_LockDummy)
{
savePoints += "entered Lock Dummy | ";
// Check once again ...
// 1. Cause the Thread ONE might have populated it _dsCacheHolder
while Thread TWO was in WAIT MODE...
// 2. Thread TWO might un-necessary re-build this Cache....
if (isCacheNotValid())
{
savePoints += "entered Cache Invalid 2 | ";
PerfCache._dsCacheHolderOut = new PA_PropertyStructure();
// DataSet dummyDS = new DataSet();
PerfCache._dsCacheHolderOut.EnforceConstraints = false;
PerfCache._dsCacheHolderOut.ReadXml(OptionsFilePath,
XmlReadMode.IgnoreSchema);
// _dsCacheHolderOut.Merge(dummyDS,true);
_dsCacheHolderOut.EnforceConstraints = true;
// dummyDS = null;
// Cache Dependency....
CacheDependency _Depends = new CacheDependency( OptionsFilePath );
// Cache Dependency....
_publishedCache.Insert("FileChanged", "false", _Depends,
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Normal,
onOptionFileChange );
savePoints += "completed the save | ";
return _dsCacheHolderOut.Copy();