none
Winform ReportViewer Background Thread

    Question

  • Hi All

    I'm currently trying to make our winform application more responsive, and I'm having a few problems with the reportviewer.

    I'm trying to call RefreshReport on a backgound thread. However, because this method call is intrinsically bound to a control that is on the UI thread, this is not allowed. There in lies my problem.

    Is there any way to refresh the report asynchronously? I'm confused as there is a method called "CancelRendering" that stops background processing of the report. But how on earth do you start it.

    Any advice would be gratefully received. Hopefully I'm just missing somthing obvious.

     

    Regards

    Darren

    Friday, September 01, 2006 9:57 AM

Answers

  • Let me give you some background on what's happening:

    The ReportViewer control is broken up into two components - the report objects (exposed as .ServerReport and .LocalReport) and the UI (the actual ReportViewer class).  The report objects store all of the state about your report.  The UI component simply calls into them to get the information it needs to display the report, parameter prompts, toolbar, etc.

    The UI component is not thread-safe, just like most controls.  But the report objects are thread safe.  When you call RefreshReport, the viewer uses a background thread to call Render on the report object.  But this is not the only time that the control calls into the report object.  The first time it needs to compile the report definition (local report) or create a session (server report) can take a long time.  If this "first time" is during RefreshReport, it will happen on the background thread.  But as you have seen, it can happen at other times.  Populating the parameters UI, for example, requires calling GetParameters, which also requires this startup penalty.

    If you want to guarantee this "first time" penalty is on a background thread, then after setting the report path and other connection/data source information, call GetParameters from a background thread.

    Tuesday, September 05, 2006 5:04 PM

All replies

  • Hi Darren,

    The RefreshReport() method is asynchronous. While this method is being executed, your form should be responsive.

    -Shamez

    Friday, September 01, 2006 7:34 PM
  • Thanks for the reponse. Yes, when rendering the actual report the method appears to be async i.e. when the view report button is pressed on the control. However, the initial call of refresh report to obtain the parameters for the report definately does not act in an async manner. When the parameter list is complicated this makes the form(application) hang while this is being built up on the server and therefore making the rest of the application unresponsive.

    So maybe a better question would be, Is there anyway to retireve the parameters for a report asynchronously?

    Regards

    Darren

    Tuesday, September 05, 2006 10:08 AM
  • Let me give you some background on what's happening:

    The ReportViewer control is broken up into two components - the report objects (exposed as .ServerReport and .LocalReport) and the UI (the actual ReportViewer class).  The report objects store all of the state about your report.  The UI component simply calls into them to get the information it needs to display the report, parameter prompts, toolbar, etc.

    The UI component is not thread-safe, just like most controls.  But the report objects are thread safe.  When you call RefreshReport, the viewer uses a background thread to call Render on the report object.  But this is not the only time that the control calls into the report object.  The first time it needs to compile the report definition (local report) or create a session (server report) can take a long time.  If this "first time" is during RefreshReport, it will happen on the background thread.  But as you have seen, it can happen at other times.  Populating the parameters UI, for example, requires calling GetParameters, which also requires this startup penalty.

    If you want to guarantee this "first time" penalty is on a background thread, then after setting the report path and other connection/data source information, call GetParameters from a background thread.

    Tuesday, September 05, 2006 5:04 PM
  • Brian,

    Thanks for the informative answer. I can definately move on from my current situation from the information you've provided.

     

    Many thanks

     

    Darren

    Thursday, September 07, 2006 1:49 PM
  • Can you tell me if setting the data source and the SetParameters call must be on a background thread as well? or will this not affect things until the Render call is made?
    Thanks,
    Matt
    Monday, February 02, 2009 8:58 PM