Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. private void RunWorkerThread()
  2.         {
  3.             do
  4.             {
  5.                 lock (_workerThread)
  6.                 {
  7.                     if (!_flushNecessary)
  8.                     {
  9.                         Monitor.Wait(_workerThread, FlushAtAge);
  10.                         _flushNecessary = false;
  11.                     }
  12.                 }
  13.  
  14.                 FlushRequest();
  15.             } while (!_disposed);
  16.         }
  17.  
  18.         private void FlushRequest()
  19.         {
  20.             lock (_queue)
  21.             {
  22.                 _count = 0;
  23.                 _strSize = 0;
  24.                 _lastFlush = DateTime.Now.Millisecond;
  25.  
  26.                 if (_queue.Count == 0)
  27.                 {
  28.                     return;
  29.                 }
  30.  
  31.                 while (_queue.Count > 0)
  32.                 {
  33.                     _flushQueue.Add(_queue.Dequeue());
  34.                 }
  35.             }
  36.  
  37.             lock (_targetsLock)
  38.             {
  39.                 var count = _autoFlushTargets.Count;
  40.  
  41.                 ILogTarget autoFlushTarget;
  42.                 for (var i = 0; i < count; i++)
  43.                 {
  44.                     autoFlushTarget = _autoFlushTargets[i];
  45.                     autoFlushTarget.Log(_flushQueue);
  46.                 }
  47.             }
  48.  
  49.             _flushQueue.Clear();
  50.         }
  51.  
  52.         #endregion
  53.  
  54.         /// <summary>
  55.         /// Releases unmanaged and - optionally - managed resources.
  56.         /// </summary>
  57.         public void Dispose()
  58.         {
  59.             LoadingNotifier.Dispose();
  60.            
  61.             _disposed = true;
  62.            
  63.             FlushRequest();
  64.  
  65.             lock (_workerThread)
  66.             {
  67.                 Monitor.Pulse(_workerThread);
  68.             }
  69.  
  70.             var count = _autoFlushTargets.Count;
  71.             for (var i = 0; i < count; i++)
  72.             {
  73.                 var target = _autoFlushTargets[i];
  74.                 target.Dispose();
  75.             }
  76.  
  77.             count = _instantTargets.Count;
  78.             for (var i = 0; i < count; i++)
  79.             {
  80.                 var target = _instantTargets[i];
  81.                 target.Dispose();
  82.             }
  83.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement