Эксепшн при создании отчета
Создаю отчет программно,
FastReport.Report report1 = new FastReport.Report();
report1.LoadFromString(rp.ReportString);
report1.Prepare();
FastReport.Export.RichText.RTFExport export = new FastReport.Export.RichText.RTFExport();
string path = "C:\1.rtf";
export.AllowOpenAfter = false;
export.Export(report1, path);
при этом вылетает Эксепшн
System.InvalidOperationException: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.DestroyHandle()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.RichObject.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.Base.Clear()
at FastReport.Base.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.Base.Clear()
at FastReport.Base.Dispose(Boolean disposing)
at FastReport.ReportPage.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at uEVP1NZnv8KmrvKVF1f.6CKWxcZEIBgKwsv9w2t.rmNd2olQv()
at FastReport.Preview.PreparedPages.Clear()
at FastReport.Preview.PreparedPages.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize()
Как избежать появления такого эксепшна?
FastReport.Report report1 = new FastReport.Report();
report1.LoadFromString(rp.ReportString);
report1.Prepare();
FastReport.Export.RichText.RTFExport export = new FastReport.Export.RichText.RTFExport();
string path = "C:\1.rtf";
export.AllowOpenAfter = false;
export.Export(report1, path);
при этом вылетает Эксепшн
System.InvalidOperationException: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on.
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.DestroyHandle()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.RichObject.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.Base.Clear()
at FastReport.Base.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at FastReport.Base.Clear()
at FastReport.Base.Dispose(Boolean disposing)
at FastReport.ReportPage.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at uEVP1NZnv8KmrvKVF1f.6CKWxcZEIBgKwsv9w2t.rmNd2olQv()
at FastReport.Preview.PreparedPages.Clear()
at FastReport.Preview.PreparedPages.Dispose(Boolean disposing)
at System.ComponentModel.Component.Finalize()
Как избежать появления такого эксепшна?
Комментарии
После того, как сделали экспорт, очистите страницы готового отчета и освободите Report:
...
export.Export(report1, path);
report1.PreparedPages.Clear();
report1.Dispose();