我有一个类库,在其中添加了UwpDesktop nuget包。相同的nuget在Windows窗体中工作正常,但在类库中不起作用

问题描述 投票:0回答:1

我已将此功能集成到我的班级库中。一切在功能上都可以正常工作,但是当涉及到GetFileFromPathAsync()时,尽管我已经添加了try catch,但似乎也没有前进,也不会引发任何异常。

我的类库函数以.dlls的输出路径在单独的文件夹中的方式工作。我使用GUI Application测试该类库,该应用程序将其资源输出到与类库相同的文件夹中。任何帮助,将不胜感激

private static async Task<string> WindowsMediaOCR(string ImagePath, LanguageEnum language)
{
    try
    {
        // ... Some code not related to below code
        var file = await StorageFile.GetFileFromPathAsync(Directory.GetCurrentDirectory() +"\\tempImage.bmp")
        var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
        var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
        var softwareBitmap = await decoder.GetSoftwareBitmapAsync();
        var ocrResult = await engine.RecognizeAsync(softwareBitmap);
        string readText = ocrResult.Text;
    }
    catch(Exception ex)
    {
        throw;
    }
}
c# uwp file-access
1个回答
0
投票

尽管我已经添加了try catch,但它似乎也不是move forward and does not throw any exception

问题是WindowsMediaOCR是异步方法,返回类型为Task<string>,因此您需要在调用该方法之前放置一个等待关键字。并请更正需要字符串返回类型的上述方法。

var str = await CorLib.WindowsMediaOCR();
© www.soinside.com 2019 - 2024. All rights reserved.