質問

If i simply call

If PrintDialog1.ShowDialog = DialogResult.OK Then
                                        PrintDocument1.Print()
                                    End If

its working fine but if i use this function in another thread then it will shows error

{"External component has thrown an exception."}

役に立ちましたか?

解決 3

Create object of PrintDialog in new thread & then call

Dim myPDia As New PrintDialog
 If myPDia.ShowDialog() = Windows.Forms.DialogResult.OK Then
    PrintDocument1.Print()
 End If

他のヒント

You have to call SetApartmentState on the thread to switch it to STA before you start the thread. This is not possible if the thread is a threadpool thread or if you are using BackgroundWorker.

This is otherwise a bad idea, the dialog won't have a parent and is likely to disappear behind another window. Nor will it act modal. By far the best solution is to display this dialog by code that runs on the main thread. The actual printing can still take place on the worker thread. Use Control.Invoke() as required.

External threads need to Invoke requests on main UI. You can't directly make a call from a Thread to make UI changes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top