StiReport.PrintAsync from Service

Stimulsoft Reports.UWP discussion
Locked
adamaka
Posts: 27
Joined: Wed Oct 10, 2012 3:18 pm

StiReport.PrintAsync from Service

Post by adamaka »

Hello again,
I got my app working to Print a report from a button by following the example in the demo application(s). My page has a button, and in the code behind file I have the following code on the Click event:

Code: Select all

            var folder = await Windows.Storage.KnownFolders.DocumentsLibrary.GetFolderAsync("FolderName");
            var labelFile = await folder.GetFileAsync("MyReport.mrt");

            // Create the report
            StiReport report = new StiReport();

            // Load the label file into the report
            await report.LoadAsync(labelFile);

            // Render the report
            await report.RenderAsync();

            // Print the report
            await StiPrintReport.PrintAsync(report);
This works fine. Now I'm going for an MVVM approach, and I moved this same exact code to a view model and fired it off with a command. That works fine too. However, if I try to move this same exact code to an IPrintService that gets injected to my view model and then called via the same command:

Code: Select all

this.printService.PrintLabel("LabelName"); 
When the original code above fires off on my service I get the following error:
Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND))
Source: mscorlib
StackTrace: at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Stimulsoft.Report.Viewer.RT.Print.StiPrintReport.<PrintAsync>d__0.MoveNext() in d:\Stimulsoft\Stimulsoft.Reports\Stimulsoft.Report.Viewer.RT\Print\StiPrintReport.cs:line 93
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AX_Receiving.Services.LabelService.<PrintLabel>d__b.MoveNext() in d:\code\AX\AX_Receiving\AX_Receiving\Services\LabelService.cs:line 126

Any Ideas on this one?
adamaka
Posts: 27
Joined: Wed Oct 10, 2012 3:18 pm

Re: StiReport.PrintAsync from Service

Post by adamaka »

Alright, never mind on this one. It was a threading issue. In my view model, I have to make my command method asynchronous and await the "this.printService.PrintLabel("LabelName");" Then it all works fine.
Andrew
Posts: 4107
Joined: Fri Jun 09, 2006 3:58 am

Re: StiReport.PrintAsync from Service

Post by Andrew »

Hello,

Great!
Locked