[英]How to Write image bytes asynchronously?
I am trying to store a file in local directory using Windows.Storage but I get an error when I try to store a second image我正在尝试使用 Windows.Storage 将文件存储在本地目录中,但是当我尝试存储第二个图像时出现错误
I am using the Windows.Storage我正在使用 Windows.Storage
async void ReceiveDecodedData(byte[] data, int width, int height)
{
StorageFolder storageFolder = KnownFolders.PicturesLibrary;
string filename = "sample" + ".jpg";
StorageFile file = await storageFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
await FileIO.WriteBytesAsync(file, data);
}
I want to write the bytes to the image without any error/exceptions.我想将字节写入图像而没有任何错误/异常。
Exception: "The process cannot access the file because it is being used by another process."例外:“该进程无法访问该文件,因为它正被另一个进程使用。”
If the method does not return a Task then you can't use it within an async/await pattern.如果该方法没有返回一个任务,那么你不能在异步/等待模式中使用它。 JSteward is correct that you should replace async void with async Task.
Jsteward 是正确的,您应该将 async void 替换为 async Task。 If you are calling the function somewhere else then create a synchronous version of the method and call the same underlying function.
如果您在其他地方调用 function,则创建该方法的同步版本并调用相同的底层 function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.