Running Designer in thread crashes
Running Designer in thread crashes
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()
});
}
OpenDesigner()
{
Thread thread = new Thread(() =>
{
StiReport rpt = new StiReport();
// (code to populate dictionary)
rpt.Design()
});
}
Running Designer in thread crashes
Hello,
Please send us the sample project which reproduces the issue for analysis.
Thank you.
Please send us the sample project which reproduces the issue for analysis.
Thank you.
Running Designer in thread crashes
I will try to create a small sample project and post it as soon as I can.
Running Designer in thread crashes
Hello,
This will be very good!
Thank you.
This will be very good!
Thank you.
Running Designer in thread crashes
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();
}
}
}
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
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.
Thank you.
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();
}
Running Designer in thread crashes
Thanks. We will give it a try.
Running Designer in thread crashes
Hello,
Ok! Let us know about the result.
Thank you.
Ok! Let us know about the result.
Thank you.