我已经编码了下一个代码: private async void WriteData() var removableDevices = KnownFolders.RemovableDevices; var externalDrives = await removableDevices.GetFoldersAsync(); var drive0 = externalDrives [0];保存文件Windows Iot Core jpg格式
var testFolder = await drive0.CreateFolderAsync("test");
var testFile = await testFolder.CreateFileAsync("test.jpg");
var byteArray = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
using (var sourceStream = new MemoryStream(byteArray).AsRandomAccessStream())
{
using (var destinationStream = (await testFile.OpenAsync(FileAccessMode.ReadWrite)).GetOutputStreamAt(0))
{
await RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
}
}
}
private async void _timer_Tick(object sender, object e)
{
DhtReading reading = new DhtReading();
int val = this.TotalAttempts;
this.TotalAttempts++;
reading = await _dht.GetReadingAsync().AsTask();
_retryCount.Add(reading.RetryCount);
this.OnPropertyChanged(nameof(AverageRetriesDisplay));
this.OnPropertyChanged(nameof(TotalAttempts));
this.OnPropertyChanged(nameof(PercentSuccess));
if (reading.IsValid)
{
this.TotalSuccess++;
this.Temperature = Convert.ToSingle(reading.Temperature);
this.Humidity = Convert.ToSingle(reading.Humidity);
this.LastUpdated = DateTimeOffset.Now;
this.OnPropertyChanged(nameof(SuccessRate));
this.WriteData();
}
this.OnPropertyChanged(nameof(LastUpdatedDisplay));
}
我的代码冻结,我想知道我怎么能保存在档案中的湿度和温度值, 这是拯救这个应用程序的最佳方式?
有人可以帮我吗?
我检查'写数据()'对树莓派2.我写信给test.jpg放在成功。问题可能出现在_timer_Tick()中。哪一行导致你的代码被冻结?你用什么设备? –
我使用Raspberry Pi 3,Windows Iot核心操作系统版本为10.0.14393.0,您是否看到过我的代码中有任何错误? –
该错误是在 #ENDIF 的#if DEBUG &&!DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION UnhandledException + =(发件人,E)=> { 如果(全球:: System.Diagnostics.Debugger.IsAttached)全局:: System.Diagnostics程序。 Debugger.Break(); // THIS LINE }; #endif } } } –