i've coded a code next: private async void WriteData() { var removableDevices = KnownFolders.RemovableDevices; var externalDrives = await removableDevices.GetFoldersAsync(); var drive0 = externalDrives[0];
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));
}
My code freeze , and i wanna know how could I save the humidity and temperature values in that archive, It is the best way to save this app ?
Someone Could Help me ?
WriteData()
on Raspberry Pi 2. I wrote to test.jpg successfully. Problem may be in _timer_Tick(). Which line cause your code freeze? What device do you use? – Rita Han