Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Background thread Performance Guidance
    text
    copied!<p>I am running a background thread in my asp.net web service application. This thread's responsibility is to hit database after a specific time and update a datatable in the Cache. The data table has around 500K rows. In task manager when I look in processes, the web dev server for first time consumes around 300,000K on next time it goes to 500,000K and some times it reaches above 1,000,000K and sometimes drop back to 500,000-600,000K. As I am doing work on my local machine so data in database is not changing. Can anyone please guide me what I am doing wrong in the code:</p> <pre><code>protected void Application_Start(object sender, EventArgs e) { Thread obj = new Thread(new ThreadStart(AddDataInCache)); obj.IsBackground = true; obj.Start(); } private void AddDataInCache() { Int32 iCount = 0; while (true) { MyCollection _myCollection = new MyCollection(); DataTable dtReferences = null; DataTable dtMainData = null; try { dtMainData = _myCollection.GetAllDataForCaching(ref dtReferences); HttpRuntime.Cache.Insert("DATA_ALL_CACHING", dtMainData, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, null); HttpRuntime.Cache.Insert("DATA_REFERENCES_CACHING", dtReferences, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null ); } catch (Exception ex) { } finally { if (_myCollection != null) _myCollection = null; } iCount++; Thread.Sleep(18000); } } </code></pre> <p>In <code>GetAllDataForCaching</code> I am getting a <code>SqlDataReader</code> from my Data Access layer as:</p> <pre><code>public DataTable GetAllDataForCaching(ref DataTable dReferenceTable) { DataTable dtReturn = new DataTable(); SqlDataReader dReader = null; try { dReader = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "[GetDataForCaching]", null); if (dReader != null &amp;&amp; dReader.HasRows) { dtReturn.Load(dReader); dReferenceTable = new DataTable(); if (dReader.HasRows) { DataTable dtSchema = dReader.GetSchemaTable(); List&lt;DataColumn&gt; listCols = new List&lt;DataColumn&gt;(); if (dtSchema != null) { foreach (DataRow drow in dtSchema.Rows) { string columnName = System.Convert.ToString(drow["ColumnName"]); DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"])); column.Unique = (bool)drow["IsUnique"]; column.AllowDBNull = (bool)drow["AllowDBNull"]; column.AutoIncrement = (bool)drow["IsAutoIncrement"]; listCols.Add(column); dReferenceTable.Columns.Add(column); } } while (dReader.Read()) { DataRow dataRow = dReferenceTable.NewRow(); for (int i = 0; i &lt; listCols.Count; i++) { dataRow[((DataColumn)listCols[i])] = dReader[i]; } dReferenceTable.Rows.Add(dataRow); } } } } finally { if (dReader != null) { if (dReader.IsClosed == false) dReader.Close(); dReader = null; } } return dtReturn; } </code></pre> <p>I am using Visual Studio 2008.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload