Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li>I hope you are properly disposing the ADO.NET objects. (This is simply good practice.) </li> <li>Any stray references will keep your <code>RateLog</code> objects from being collected by the GC.</li> </ol> <p>I recommend you look through your code starting where the <code>RateLog</code> objects are being created and take note of all the places a reference is being held. Here are some things to consider.</p> <ol> <li>Are the <code>RateLog</code> objects subscribed to any events?</li> <li>Are you keeping a collection of <code>RateLog</code> objects sitting somewhere in a static class?</li> </ol> <p>You should also consider encapsulating all your thread safety boilerplate in class.</p> <pre><code>public sealed class WorkQueue&lt;T&gt; { private readonly System.Collections.Generic.Queue&lt;T&gt; _queue = new System.Collections.Generic.Queue&lt;T&gt;(); private readonly object _lock = new object(); public void Put(T item) { lock (_lock) { _queue.Enqueue(item); } } public bool TryGet(out T[] items) { if (_queue.Count &gt; 0) { lock (_lock) { if (_queue.Count &gt; 0) { items = _queue.ToArray(); _queue.Clear(); return true; } } } items = null; return false; } } </code></pre> <p>This will make your code a lot clearer:</p> <pre><code>protected void FetchingRates() { int ratesInterval = int.Parse(ConfigurationManager.AppSettings["RatesIntreval"].ToString()); int count = 0; var queue = new WorkQueue&lt;RateLog&gt;(); while (true) { try { var items = default(RateLog[]); if (queue.TryGet(out items)) { foreach (var item in items) { m_ConnectionDataAccess.InsertRateLog(item); } } } catch (Exception ex) { Logger.Log(ex); } Thread.Sleep(ratesInterval); count++; } } </code></pre>
 

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