コード例 #1
0
        /// <summary>
        /// Demonstrate the use of the GetQueuedDataFeed
        /// This method is similiar to GetDataFeed, except it buffers the DataSamples from iRacing
        /// This allow loops that occasionally take a little longer then 1/60th of a second.
        /// But it also means that the DataSamples yield into the enumeration may be a little out of date.
        /// </summary>
        public static void Sample()
        {
            var iracing = new iRacingConnection();

            iracing.Replay.MoveToStart();
            iracing.Replay.SetSpeed(1);

            var lastSector = new LapSector();
            var i          = 0;

            foreach (var data in iracing.GetBufferedDataFeed(10))
            {
                if (data.Telemetry.RaceLapSector != lastSector)
                {
                    Trace.WriteLine(string.Format("Lap: {0} Sector: {1}", data.Telemetry.RaceLapSector.LapNumber, data.Telemetry.RaceLapSector.Sector));
                }

                if (i > 1)
                {
                    Debug.Assert(data.LastSample != null, "LastSample should not be null");
                }

                lastSector = data.Telemetry.RaceLapSector;

                if (i++ % 10 == 1)
                {
                    Trace.WriteLine("Pausing retrieval of data samples - simulating work");
                    Thread.Sleep(100);
                }
            }
        }