Running Designer in thread crashes

Stimulsoft Reports.NET discussion
Post Reply
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Running Designer in thread crashes

Post by jmiller »

I have an app that creates a report, creates the data source, and then starts the designer. This happens in a thread. If I close the designer and then try running it a second time from my app and exception is thrown. If I open the designer twice without closing the first one, there is no exception. The exception occurs on the call to Design(). The message is: "Cross-thread operation not valid: Control " accessed from a thread other than the thread it was created on".

OpenDesigner()
{
Thread thread = new Thread(() =>
{
StiReport rpt = new StiReport();
// (code to populate dictionary)
rpt.Design()
});
}
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Running Designer in thread crashes

Post by Alex K. »

Hello,

Please send us the sample project which reproduces the issue for analysis.

Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Running Designer in thread crashes

Post by jmiller »

I will try to create a small sample project and post it as soon as I can.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Running Designer in thread crashes

Post by Andrew »

Hello,

This will be very good!

Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Running Designer in thread crashes

Post by jmiller »

I created a very basic WinForms program. Just added a button on the form to start the designer. The full code is below. So, I click the button, the designer starts. I close the designer, go back to my form and click the button again. This is where it crashes.

namespace StimulsoftSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(() =>
{
Stimulsoft.Report.StiReport rpt = new Stimulsoft.Report.StiReport();

rpt.Design();

});

thread.IsBackground = false;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

}

}
}
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Running Designer in thread crashes

Post by Alex K. »

Hello,

In this case, your application is marked as SAT, in other words any form of application should be shown in the main stream (only in it) and nothing else. Besides you cannot use the MTA, because WinForms can only work with the STA. WinForms does not support MTA because it actively uses OLE objects, and, in particular, Drag’n’Drop.
We have an option, disabling Drag'n'Drop, it is not quite correct, but this should help.

Code: Select all

private void button1_Click(object sender, EventArgs e)
{
    Stimulsoft.Report.StiOptions.Designer.AllowUseDragDrop = false;
    Thread thread = new Thread(() =>
        {
            Stimulsoft.Report.StiReport rpt = new Stimulsoft.Report.StiReport();
            rpt.Design();
        });

    thread.IsBackground = false;
    thread.SetApartmentState(ApartmentState.MTA);
    thread.Start();
}
Thank you.
jmiller
Posts: 91
Joined: Mon Sep 20, 2010 12:18 pm

Running Designer in thread crashes

Post by jmiller »

Thanks. We will give it a try.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Running Designer in thread crashes

Post by Andrew »

Hello,

Ok! Let us know about the result.

Thank you.
Post Reply