0

I have created function into that I have created one lock so no other one access that code until first call finish. Under this lock I am running parallel threads and into that thread I am calling function which also have there own lock but some how first lock is not working after sometime and application get crash.

static readonly object _syncCoreLock = new object();

internal void ExecuteCatalogTablePopulationThreads()
    {
        lock (_syncCoreLock)
        {
            currentContext = System.Web.HttpContext.Current;
            System.Collections.ObjectModel.Collection<System.Action> actions = this.CheckCacheAndExecuteActionIfCacheExpired();

            if (actions.Count > 0)
            {
                System.Action[] methodsToExecute = new System.Action[actions.Count];
                actions.CopyTo(methodsToExecute, 0);
                homeCategoryId = DefaultParametersForCatalog.HomeCategoryId.ToString();
                System.Threading.Tasks.Parallel.Invoke(new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = actions.Count }, methodsToExecute);
            }

            this.ExecuteMetaTablesQueryInMultipleThreads<AttributeStringMetaDictionary>();

            if (this.isExecuteProductMetaAttributeQueryThread || this.isExecuteSkuMetaAttributeQueryThread)
            {
                this.SearchDataDictionary = new System.Collections.Generic.Dictionary<int, SearchKeywordDictionary>();
                System.Threading.Tasks.Parallel.Invoke(new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = 3 },
                    () => this.ExecuteQualifierTableInThread<ProductQualifier>(),
                    () => this.ExecuteCrossSellingTableInThread<CrossSellingProduct>(),
                    () => this.ExecuteProductSkuMapping());
            }

            if (this.isExecuteCategoryMetaAttributeQueryThread || this.isExecuteProductMetaAttributeQueryThread)
                System.Threading.Tasks.Parallel.Invoke(new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = 2 },
                                                        () => this.ExecuteProductCategoryAndQualifierMapping(),
                                                        () => this.ExecuteCategoryMetaFieldMapping());

            if (this.isExecuteProductMetaAttributeQueryThread || this.isExecuteSkuMetaAttributeQueryThread)
            {
                this.ExecuteProductMetaFieldMapping();
                this.ExecuteSkuMetaFieldMapping();

                this.ExecuteCrossSellingProductMapping();

                this.SearchKeyWordDataDictionary = new System.Collections.Generic.HashSet<SearchKeywordDictionary>(this.SearchDataDictionary.Values);
                Cache.Insert(searchDataDictionaryCacheKey, this.SearchKeyWordDataDictionary);
            }

            if (this.isExecuteDiscountMappingThread)
                ExecuteProductDiscountMapping(); 
 }
}

It throw below error sometime :

System.AggregateException: One or more errors occurred. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache2.Resize() at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache2.Find(K key, T& value, Boolean add) at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache2.InsertLookup(Object instance) at System.Data.Linq.IdentityManager.StandardIdentityManager.InsertLookup(MetaType type, Object instance) at System.Data.Linq.CommonDataServices.InsertLookupCachedObject(MetaType type, Object instance) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase1.InsertLookup(Int32 iMetaType, Object instance) at Read_UpSellingProduct(ObjectMaterializer1 ) at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader2.MoveNext()

can anybody tell me what is the problem?

Thanks, Sandy

Sandy
  • 57
  • 1
  • 17

0 Answers0