예제 #1
0
 /// <summary>
 /// StopReading
 /// Terminates NMEA reading process
 /// </summary>
 public void StopReading()
 {
     ReadCancellationTokenSource.Cancel();
     if (null != ReadTask)
     {
         ReadTask.Wait();
         ReadTask = null;
     }
 }
예제 #2
0
        /// <summary>
        /// Reads data from the process output
        /// </summary>
        /// <param name="Buffer">The buffer to receive the data</param>
        /// <param name="Offset">Offset within the buffer to write to</param>
        /// <param name="Count">Maximum number of bytes to read</param>
        /// <returns>Number of bytes read</returns>
        public int Read(byte[] Buffer, int Offset, int Count)
        {
            // Fill the buffer, reentering managed code every 20ms to allow thread abort exceptions to be thrown
            Task <int> ReadTask;

            if (FrameworkProcess == null)
            {
                ReadTask = InnerStream.ReadAsync(Buffer, Offset, Count);
            }
            else
            {
                ReadTask = FrameworkProcess.StandardOutput.BaseStream.ReadAsync(Buffer, Offset, Count);
            }
            while (!ReadTask.Wait(20))
            {
                // Spin through managed code to allow things like ThreadAbortExceptions to be thrown.
            }
            return(ReadTask.Result);
        }