private void ThreadLoop() { var currentEventCounter = 0; const int softDumpPortion = 10; var stopwatch = new Stopwatch(); while (true) { if (_mode == Mode.Stop || _mode == Mode.Pause) { return; } stopwatch.Start(); Profile.VariableStorage.SynchronizeVariables(); Work(); if (!ApplicationSettings.ControlsSynchronizationIsOff) { var eventsCache = HardwareManager.SoftDump(); if (eventsCache != null) { var softDumpEvents = eventsCache.Skip(currentEventCounter).Take(softDumpPortion).ToArray(); if (softDumpEvents.Length != 0) { currentEventCounter += softDumpPortion; foreach (var controlEvent in softDumpEvents) { controlEvent.IsSoftDumpEvent = true; Profile.ControlProcessor.SendEvent(controlEvent); } } else { currentEventCounter = 0; } } } stopwatch.Stop(); const int delay = 200; if (stopwatch.ElapsedMilliseconds < delay) { Thread.Sleep(delay - (int)stopwatch.ElapsedMilliseconds); } } }