Page 1 of 1

Running Designer in thread crashes

Posted: Tue May 10, 2011 10:36 am
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()
});
}

Running Designer in thread crashes

Posted: Wed May 11, 2011 8:30 am
by Alex K.
Hello,

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

Thank you.

Running Designer in thread crashes

Posted: Wed May 11, 2011 12:20 pm
by jmiller
I will try to create a small sample project and post it as soon as I can.

Running Designer in thread crashes

Posted: Thu May 12, 2011 12:58 am
by Andrew
Hello,

This will be very good!

Thank you.

Running Designer in thread crashes

Posted: Fri May 13, 2011 7:40 am
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();

}

}
}

Running Designer in thread crashes

Posted: Mon May 16, 2011 2:06 am
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.

Running Designer in thread crashes

Posted: Mon May 16, 2011 1:49 pm
by jmiller
Thanks. We will give it a try.

Running Designer in thread crashes

Posted: Mon May 16, 2011 2:02 pm
by Andrew
Hello,

Ok! Let us know about the result.

Thank you.