public async Task ReadAsync(int count, IProgress <byte[]> progress) { decimal reads = Math.Ceiling(((decimal)count / ioLimit)); byte[] data; await Task.Run(async() => { for (int i = 0; i < reads; i++) { int readOffset = i * ioLimit; int readAddress = (int)Position + readOffset; int readLength = Math.Min(count - readOffset, ioLimit); List <byte> outputBytes = new List <byte>(); outputBytes.AddAll(BitConverter.GetBytes(readAddress)); outputBytes.Add((byte)readLength); byte[] output = outputBytes.ToArray(); Console.WriteLine($"SPI read ({i + 1}/{reads})..."); PacketData packet = await command.SendSubcommandAsync(0x1, 0x10, output, (p) => p.Data.Take(output.Length).SequenceEqual(output) // check that read is the one requested ); data = packet.Data.Skip(output.Length).Take(readLength).ToArray(); progress.Report(data); } }); }