- Joined
- Apr 18, 2008
- Messages
- 1
- Reaction score
- 0
How to invoke an STA delegate from an MTA thread? Is marshaling required?
In a background worker threads are MTA, while UI threads must be STA. Attempting to instantiate a form class in a background worker throws an exception, so invocation of a delegate is required.
My problem is that I have encapsulated all of my twain driver code into a plain class with no form which I instantiate in the background worker. If the scanner is not loaded I need to display a simple dialog, so I created a delegate on the main form, but when I call My.Forms.Form1.myDialogDelegate.Invoke(), the delegate reports that it's apartment state is MTA and it still will not display a dialog.
How can I force a delegate call to another thread to execute as an STA thread when called from an MTA thread? Is marshaling required?
In a background worker threads are MTA, while UI threads must be STA. Attempting to instantiate a form class in a background worker throws an exception, so invocation of a delegate is required.
My problem is that I have encapsulated all of my twain driver code into a plain class with no form which I instantiate in the background worker. If the scanner is not loaded I need to display a simple dialog, so I created a delegate on the main form, but when I call My.Forms.Form1.myDialogDelegate.Invoke(), the delegate reports that it's apartment state is MTA and it still will not display a dialog.
How can I force a delegate call to another thread to execute as an STA thread when called from an MTA thread? Is marshaling required?
Last edited: