locked
winRT app gets freezed and/or crashes while assigning VirtualSurfaceImageSource

    Question

  • I am creating image from pdfpage using VirtualSurfaceImageSource. but when zoom factor is greater than 2, app gets freezed and/or crashes. and it takes too much time for assigning image source. sample code is given below. is there any idea to solve this problem?

    private void Zoom_Click(object sender, RoutedEventArgs e)
    {
                if (!zoomstarted)
                {
                    zoomstarted = true;
                    ThreadPoolTimer zoomtimer;
                  zoomtimer = ThreadPoolTimer.CreateTimer(UpdatePages, TimeSpan.FromSeconds(5));
                       
                } 

    }

    private async void UpdatePages(ThreadPoolTimer timer)

    {
                await  Dispatcher.RunAsync(CoreDispatcherPriority.High, RenderPage);
    }

    private async void RenderPage()
    {
                try
                {               
                    Size pagesize;
                    pagesize.Height = Window.Current.Bounds.Height;
                    pagesize.Width = Window.Current.Bounds.Width;
                    string path="";
                    try
                    {
                         path = Package.Current.InstalledLocation.Path.ToString() + "\\Assets\\book.pdf";
                        pdffile = await StorageFile.GetFileFromPathAsync(path);
                        doc = await PdfDocument.LoadFromFileAsync(pdffile);
                    }
                    catch ()
                    {
                      
                    }

                    if (doc != null)
                    {
                        pdf_page = doc.GetPage(0);
                    }

                    if (pdfpage1 == null)
                    {

                          pdfpage1 = new PdfDocViewModel(pdf_page, pagesize, SurfaceType.VirtualSurfaceImageSource);
                    }
                 
                    pdfpage1.UpdatePages(2)
                 Image.Source = ((PdfPageViewModel)pdfpage1[0]).ImageSourceSis; Image.Source = ((PdfPageViewModel)pdfpage1[0]).ImageSourceVsisForeground;

                }
                catch
                {
                   
                }
                zoomstarted = false;
            }

    Thanks in advance

    Saturday, June 21, 2014 7:31 AM

All replies

  • Please post a project to OneDrive and share the link to it here.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 23, 2014 7:12 PM
    Moderator
  • Hi Matt Small,

    Thanks for your reply. As you suggested I have posted sample on OneDrive. Below is the link to that code,

    https://skydrive.live.com/redir?resid=6834830A45FD9C4C!153

    Tuesday, June 24, 2014 5:24 AM