/// <summary> /// The thread funktion to poll the telemetry data and send TelemetryUpdated events. /// </summary> private void Run() { RF2Data lastTelemetryData = new RF2Data(); Stopwatch sw = new Stopwatch(); sw.Start(); while (!isStopped) { try { // get data from game, // if an exception will be thrown, we could not retrieve the data because the game // is not running or something went wrong RF2Data telemetryData = (RF2Data)readSharedMemory(typeof(RF2Data), sharedMemoryFile); // otherwise we are connected IsConnected = true; if (telemetryData.time != lastTelemetryData.time) { IsRunning = true; sw.Restart(); TelemetryEventArgs args = new TelemetryEventArgs( new RF2TelemetryInfo(telemetryData, lastTelemetryData)); RaiseEvent(OnTelemetryUpdate, args); lastTelemetryData = telemetryData; } else if (sw.ElapsedMilliseconds > 500) { IsRunning = false; } Thread.Sleep(SamplePeriod); } catch (Exception e) { LogDebug("RF2TelemetryProvider Exception while processing data", e); IsConnected = false; IsRunning = false; Thread.Sleep(1000); } } IsConnected = false; IsRunning = false; }
public RF2TelemetryInfo(RF2Data telemetryData, RF2Data lastTelemetryData) { _telemetryData = telemetryData; _lastTelemetryData = lastTelemetryData; }