Example #1
0
        private async void RemovePageTask(int pageId, TaskInfo taskInfo)
        {
            DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[pageId];

            Console.WriteLine("移除页面:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
            UIElement uiElement = target.Child;

            uiElement = null;
            target.SetValue(ContentPresenter.ContentProperty, null);

            await target.SetChildAsync <Border>(() =>
            {
                Console.WriteLine("移除页面await:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
                return(new Border());
            }
                                                , () =>
            {
                Border bd = new Border();
                pageQueueList[pageId].list.Remove(taskInfo);
                if (pageQueueList[pageId].list.Count > 0)
                {
                    RemovePageTask(pageId, pageQueueList[pageId].list[0]);
                }
                return(bd);
            });
        }
Example #2
0
        private async void LoadPageTask(int pageId, TaskInfo taskInfo)
        {
            DispatcherContainer target = (DispatcherContainer)contentStackPanel.Children[pageId];

            // if (target.Child != null && target.Child is FixedPage) return;
            //  if (target.GetIsUpdatingChild()) return;
            // Console.WriteLine("获取页面:" + pageId);
            Console.WriteLine("获取页面:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);

            //await 回调,执行下一个
            await target.SetChildAsync <FixedPage>(() =>
            {
                FixedPage fp = new FixedPage();
                try
                {
                    XpsDocument xpsDoc = new XpsDocument(wordFullPath, FileAccess.Read);
                    FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
                    foreach (DocumentReference DocRef in fixedDocumentSequence.References)
                    {
                        Console.WriteLine("获取页面await:" + pageId + "___ThreadId:" + Thread.CurrentThread.ManagedThreadId);
                        Console.WriteLine();
                        bool bForceReload       = false;
                        FixedDocument DocFd     = DocRef.GetDocument(bForceReload);
                        PageContent pageContent = DocFd.Pages[pageId];
                        fp = pageContent.GetPageRoot(false);

                        // pageContent.SetValue(ContentPresenter.ContentProperty, null);

                        //for (int i = 0; i < fixedPage.Children.Count; i++)
                        //{
                        //    UIElement uiElement = fp.Children[i];
                        //    fixedPage.Children.Remove(uiElement);
                        //    fp.Children.Add(uiElement);
                        //}
                    }
                    // xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
                    return(fp);
                }
                catch (Exception)
                {
                    return(fp);
                }
            }
                                                   , () =>
            {
                FixedPage fp = new FixedPage();
                pageQueueList[pageId].list.Remove(taskInfo);
                if (pageQueueList[pageId].list.Count > 0)
                {
                    LoadPageTask(pageId, pageQueueList[pageId].list[0]);
                }
                return(fp);
            });


            //  Console.WriteLine("任务是否完成:"+task.IsCompleted);
        }