This is a migrated thread and some comments may be shown as answers.

How to Stop reportProcessor.PrintReport()

3 Answers 238 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Fernando
Top achievements
Rank 1
Fernando asked on 08 Sep 2020, 07:30 PM

I want to be able to stop the execution of the ReportProcessor.PrintReport() and throw a custom error when the printer is unavailable (e.g: disconnected from the server) because instead of doing that the method is trying to find the printer and it freezes. if that's not possible a way to exit the method (timer?) would be good as well.

 

Regards,

 

Gaston.

 

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 11 Sep 2020, 11:55 AM

Hello Gaston,

The ReportProcessor.PrintReport method may take a CancellationToken as an argument. You may start the report printing/rendering in a different thread and stop it from the main thread, for example, if it doesn't return a result in some time.

Regards,
Todor
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

0
Fernando
Top achievements
Rank 1
answered on 11 Sep 2020, 02:36 PM
Hi Todor, thanks for your answer, do you have an example on how to use the cancellation token from the main thread to a secondary thread like that?
0
Todor
Telerik team
answered on 16 Sep 2020, 04:36 PM

Hi Gaston,

I spoke with a developer, and he explained that the cancellationToken passed with the PrintReport method gets checked when the report is processed and rendered. When the printer is not available, report processing won't start, hence the checks in our code won't be hit. For that reason, we will suggest an alternative solution.

I have attached a sample Windows Forms project. On the Print button click, we open a new task called managerTask. The idea is to keep the UI thread unoccupied so that it doesn't hang and invoke printing from another thread instead. The managerTask thread starts the print task printingTask that is the actual printing. If printing takes more than expected (in this case 5s), the cancellation token will be set in the managerTask, and later, if printing continues, e.g. printer gets found, the printing will be canceled by our code.

The Trace Listener that is attached to the project logs how the printing has gone - see the App.config for the log file path. Note that we simulated unsuccessfully/slow printing with 'Thread.Sleep(10000);' and you need to remove this code.

Regards,
Todor
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Report Designer (standalone)
Asked by
Fernando
Top achievements
Rank 1
Answers by
Todor
Telerik team
Fernando
Top achievements
Rank 1
Share this question
or