/// <summary> /// Método acionado pelo robo do processador. /// </summary> protected void Run() { while (_worker != null) { IAsyncTask task = null; try { lock (this) { if ((_eventsHi.Count < 1) && (_eventsLow.Count < 1)) { Monitor.Wait(this); } if (_eventsHi.Count > 0) { task = _eventsHi.Dequeue(); } else if (_eventsLow.Count > 0) { task = _eventsLow.Dequeue(); } } if (task != null) { task.Process(); } continue; } catch (ThreadAbortException) { break; } catch (NullReferenceException) { continue; } catch (Exception) { continue; } } }
/// <summary> /// Thread function, keeps running. /// </summary> protected void Run() { while (_started) { IAsyncTask evnt = null; try { lock (this) { if ((_eventsHi.Count < 1) && (_eventsLow.Count < 1) && !_isShutdown) { Monitor.Wait(this); } if ((_eventsHi.Count < 1) && _isShutdown) { lock (_shutdownMutex) { Monitor.PulseAll(_shutdownMutex); break; } } if (_eventsHi.Count > 0) { evnt = (IAsyncTask)_eventsHi.Dequeue(); } else if (_eventsLow.Count > 0) { evnt = (IAsyncTask)_eventsLow.Dequeue(); } } if (evnt == null && _eventsHi.Count < 1 && _isShutdown) { lock (_shutdownMutex) { Monitor.PulseAll(_shutdownMutex); break; } } if (evnt == null) { continue; } evnt.Process(); } catch (ThreadAbortException e) { if (NCacheLog != null) { NCacheLog.Flush(); } break; } catch (ThreadInterruptedException e) { if (NCacheLog != null) { NCacheLog.Flush(); } break; } catch (NullReferenceException nr) { } catch (Exception e) { string exceptionString = e.ToString(); if (exceptionString != "ChannelNotConnectedException" && exceptionString != "ChannelClosedException") { if (NCacheLog != null) { NCacheLog.Error("AsyncProcessor.Run()", "Task name: " + evnt.GetType().FullName + " Exception: " + exceptionString); } } } } }