private void run() { try { bool isInError = false; bool isSynchronizing = false; while (stopRequired == 0) { if (eventList.Count == 0) { isSynchronizing = false; // Wait a little to let the user see the previous status Thread.Sleep(300); if (!isInError) { statusListener.onListening(); } } FsEvent fsEvent = eventList.Take(); if (!isSynchronizing) { isSynchronizing = true; if (!isInError) { statusListener.onSynchronizing(); } } if (!fsEvent.poison) { long diff = Math.Abs(Environment.TickCount64 - fsEvent.timeStamp); if (diff < 1000) { Thread.Sleep((int)(1000 - diff)); } int nTries = 0; while (true) { try { processEvent(fsEvent); break; } catch (Exception e) { nTries++; if (nTries >= 10) { Logger.log(Logger.Level.Info, "Process event in error after 10 attemps."); Logger.log(Logger.Level.Info, e); isInError = true; statusListener.onError(); break; } else { Logger.log(Logger.Level.Debug, $"Retry {nTries}"); Thread.Sleep(500); } } } } } } catch (Exception e) { Logger.log(Logger.Level.Info, e); } }