var printItem = new MenuItem { Header = "Print..." };printItem.Click += (sender, e) => {
var reportSection = new EmbeddedVisualReportSection(this); var report = new Report(); report.Sections.Add(reportSection); report.Export(OutputFormat.XPS, @"c:\test.xps"); // Exports fine the entire grid. report.Print(); //throws CrossThread exception
};gridMenu.Items.Add(printItem);
What could be the reason?
More information:
App is multithreaded.
report.Print(false, false) is printing. But printing without PrintDialog does not make sense for us.
Can you look into this issue please?
This link might help:
http://stackoverflow.com/questions/2972513/printdialog-in-multithreaded-wpf-window-thrown-targetinvocationexception
I would appreciate any feedback on that issue.
Thanks
Sam,
Sorry for not being clear. Rewind, here is the scenario:
- this is an app with multiple UI threads
- the grids could be running on any of those UI threads
- of course the printing would be done in the same thread as the grid was created in
- however, it would not work, but would yield exception as per above
Printing only would work as the grid (and the printed report) are running in the application "main thread"
-> Basically you can't have the grids running outside the main thread
Please let me know if the issue still would not be clear and you needed more info.
Dierk,
Grid can run outside the main thread, but if the report object is created on the same thread where the grid is running, then printing the report will fail.
This is a limitation, and I can submit a feature request on your behalf if you prefer.
Thanks,
Sam
Thanks for your feedback.
However, I'm confused: are you saying that I can't have grids in separate threads, since I can't print them?
This would render the grids useless for us, since our improved app design has multiple UI threads.
Could you please clarify?
Hello Dierk,
The grid can be on any thread. The framework does not allow property access across threads. In this case it is trying to access the Report object in another thread and that is currently not supported. You need to go back to the main thread.
Thanks.
Hmm .. you 're loosing me here. Could you please point out - may be on the code of my initial post - which lines should be executed in what thread?
Would be great...
We are bouncing back and forward. I have created different thread for different problem:
http://community.infragistics.com/forums/p/51097/267692.aspx#267692
I should say Microsoft PrintDialog not ReportDialog, in the link you provided.
Sorry, which "ReportDialog" are you reffering to?
Somehow my response is not showing in this thread. I am not sure if you received it somehow.
Earlier today I have commented that this issue appeared to me Microsoft related bug with ReportDialog as Andrew pointed out, and our Report class is using WPF ReportDialog.
As I stated PrintingDialog issue has been resolved for now, but I described the different issue about how grid is printed or exported to XPS file. It is not related to printing since exporting to xps does the same thing. Please see couple posts above.