为什么PDFTron PDFViewCtrl.Update()会抛出AccessViolationException异常。

4
我将使用PDFTron PDF注释库在我的Windows商店应用程序项目中。有时,当我尝试将先前完成的注释(保存为单独的文件)加载到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;
    }

1
异常调用堆栈是什么? - Matt
错误信息: {"尝试读取或写入受保护的内存。这通常是其他内存已损坏的迹象。"} - SurenSaluka
1
这是异常消息,不是调用堆栈。 - Matt
堆栈跟踪:在pdftron.PDF.PDFViewCtrl.Update()处 在com.IronOne.BoardPACWinApp.View.Page.NewsAndShardDocsPage.<LoadPaperCommon>d__4d.MoveNext()处 在System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.InvokeMoveNext(Object stateMachine)处 在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)处 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)处 - SurenSaluka
1个回答

4
您正在后台线程中渲染文档时修改该文档。在跨线程写入和读取共享数据时,可能会导致随机错误,就像您遇到的那样。您需要在 this.PDFViewCtrl.DocLock(true)this.PDFViewCtrl.DocUnlock() 中开始和结束 ImportAnnotations 函数。
更多关于此主题的详细信息,请参见此论坛帖子

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接