I have a problem with the saving of the content of an InkCanvas in a UWP App. In Debug Mode it all works perfectly. In Release Mode, I cannot save it.
The blob in the sqlite DB is empty all the time (in Release Mode).
Here is my Code:
static public byte[] GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
outputStream.FlushAsync();
}
return ms.ToArray();
}
Maybe a UWP pro can help me :)
Thanks Agredo
I have a problem with the saving of the content of an InkCanvas in a UWP App. In Debug Mode it all works perfectly. In Release Mode, I cannot save it.
Release Compiling use .Net Native by default. So there are some different behaviors compared with debug mode.
In this case,CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync
and outputStream.FlushAsync
are async functions, you need to add await
before them. So your codes should look like this:
static public async Task<byte[]> GetByteArray(InkCanvas CardInkCanvas) {
MemoryStream ms = new MemoryStream();
// Write the ink strokes to the output stream.
using(IOutputStream outputStream = ms.AsOutputStream()) {
//Add await before async functions so that the async functions get executed before return.
await CardInkCanvas.InkPresenter.StrokeContainer.SaveAsync(ms.AsOutputStream());
await outputStream.FlushAsync();
}
return ms.ToArray();
}