c# - 为什么 PDFTron PDFViewCtrl.Update() 抛出 AccessViolationException

标签 c# windows-store-apps pdftron

我在我的 Windows 应用商店应用程序项目中使用 PDFTron PDF 注释库。有时,当我尝试将以前完成的注释(另存为单独的文件)加载到 PDFView 控件时,它会抛出 AccessViolationException。 请帮忙。

在我的页面上,这是代码:

await ImportAnnotations(param.Doc, agendaItem);
this.PDFViewCtrl.Update(); //this is where the exception throws

这是 ImportAnnotations 函数。

private async Task<PDFDoc> ImportAnnotations(PDFDoc doc, AgendaItem GlobalSelectdAgendaItem)
    {
        try
        {
            if (doc != null && GlobalSelectdAgendaItem != null)
            {
                StorageFolder documentsFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(ApplicationData.Current.LocalFolder.Path, Global.UserId.ToString(), ApplicationConstants.PDF));
                string annotationFileName = GlobalSelectdAgendaItem.ID + "_" + Global.UserId.ToString() + "_" + GlobalSelectdAgendaItem.VersionId + ".xfdf";

                // load XFDF annotations
                var anntotationFile = await documentsFolder.TryGetItemAsync(annotationFileName) as IStorageFile;
                FDFDoc fdfDoc = null;
                if (anntotationFile != null)
                {
                    fdfDoc = await FDFDoc.CreateFromXFDFAsync(Path.Combine(documentsFolder.Path, annotationFileName));
                }
                else
                {
                    return doc;
                }

                // load PDF with which to merge the annotations
                doc.InitSecurityHandler();

                // merge in the annotations
                doc.FDFMerge(fdfDoc);
                doc.RefreshFieldAppearances();
            }
        }
        catch (Exception)
        {
        }
        return doc;
    }

最佳答案

您正在修改正在后台线程中呈现的文档。跨线程写入共享数据,同时读取它们,可能会导致您遇到的随机错误。

您需要使用 this.PDFViewCtrl.DocLock(true)this.PDFViewCtrl.DocUnlock()

开始和完成您的 ImportAnnotations 函数

See this forum post for more details on this topic

关于c# - 为什么 PDFTron PDFViewCtrl.Update() 抛出 AccessViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31005338/

相关文章:

c# - 方法作为 Microsoft Solver Foundation 中的目标函数?

C# - 意外的身份验证方法 mysql_native_password 异常

c# - 如何在重定向页面之前获取警报消息

windows-store-apps - 更新专辑封面 Windows 8.1 Store 应用程序

uwp - 如何更新 Windows 10 UWP 商店证书

ios - PDFTron:带有自定义图像的 PTFileAttachment 未显示

javascript - 如何使用 contents-richtext 导出自由文本注释

ios - 测试 PDFTron/PDFNet - 添加 libTools.a 时找不到符号

c# - 如何将两个表连接成一个新表以在 C# 中显示?

node.js - 从现有 Exe 创建适用于 Windows 应用商店的应用程序包