WinForms ReportViewer pending application WPF

I've been having some problems with ReportViewer Basically, the code is as follows:

public void Display(object dataSource,ReportViewer viewer)
    {
        currentDs = dataSource as MyTypes;

        if (currentDs != null)
        {
            var param = new LinkedList<ReportParameter>();
            param.AddFirst(new ReportParameter("Title","Title"));
            viewer.ProcessingMode = ProcessingMode.Local;
            viewer.LocalReport.ReportEmbeddedResource = ReportName;
            viewer.LocalReport.EnableExternalImages = true;
            viewer.LocalReport.DataSources.Add(new ReportDataSource(DataSourceName + "_Header",currentDs.Header));
            viewer.LocalReport.DataSources.Add(new ReportDataSource(DataSourceName + "_Footer",currentDs.Footer));
            viewer.LocalReport.DataSources.Add(new ReportDataSource(DataSourceName + "_Lines",currentDs.Lines));

            viewer.LocalReport.SetParameters(param);
            viewer.RefreshReport();
        }
    }

The problem is that sometimes it generates RDLC reports, but others just hang the application Specifically, it remains in the viewer RefreshReport(); Forever

The corresponding parameters and data sets are set correctly in the RDLC file

Has anyone experienced similar behavior?

Thank you in advance

Solution

I may have fixed it This page helps me solve: http://ikriv.com/dev/dotnet/MysteriousHang.html

Therefore, it seems that a) the report viewer needs to be created on the UI thread, and b) it does not always happen reliably (see the link for details) The report viewer is Net 2 component, the behavior recorded in the link is applicable to NET 2.

To solve this problem, I used the following techniques:

>The first trick: name the UI thread at startup > the second trick: force the handle as soon as possible, and then obtain the reference to the synchronization context > the third trick: use the thread name and synchronization context to realize the required call – > call idiom

If everything comes together, I'll come back and release more details

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>