我在 C# 类中有一个异步方法
namespace ImageHolder
{
public sealed class BlankFilter
public async Task<InMemoryRandomAccessStream> applyFilter()
{
inputStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inputStream);
/* more code */
}
}
我通过以下方式从 WinJS 类调用此函数
filter.applyFilter().then(function (memStream) {
var msStream = MSApp.createStreamFromInputStream("image/jpeg", memStream);
var imageURL = URL.createObjectURL(msSteam);
id("imageInput").src = imageURL;
});
但是,这不起作用,Visual Studio 抱怨返回类型应更改为 IAsyncAction。这样做也无济于事。
那么,从 WinJS 代码调用具有 await 的 C# 函数的正确方法是什么?