I have designed a multithreaded app, which is starting most windows in an dedicated thread like this:
Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
newWindowThread.Start();
However, if in one of those window-in-own-thread I try to print something by simply calling
PrintDialog pDialog = new PrintDialog();
bool? doPrint = pDialog.ShowDialog();
I get a TargetInvocationException – it does look like the PrintDialog does not reside in the same thread as my window.
Is there any way to create a thread-agnostic (or “thread-save”) PrinterDialog ?
The answer is here:
Someone built a Thread-Enabled PrintDialog here. This seems to be the only way to get Printing working in an Thread-Enabled app.
(I’d loved to repeat the code here, but it exceeds the maximum length of answers)
Remark:
are needed references.