To work around this problem, make sure that the instantiating thread runs in an STA.
If you use the
MTAThread attribute to specify that the main thread of the host application runs in an MTA, you must use the
STAThread attribute instead. To do this, follow these steps:
- In the code for your host application, locate the following code:
- Replace the code that you located in the previous step with the following code:
- Build your host application, and then run your host application.
The problem that is mentioned in the "Symptoms" section does not occur.
If you start a new thread without specifying the apartment state of the thread, you must specify the apartment state of the thread as single-threaded. To do this, follow these steps:
- If you start a thread that is named MyThread in the code for your host application, locate the following code:
- Add the following code before the code that you located in the previous step:
' Specify that the MyThread thread runs in an STA.
MyThread.ApartmentState = Threading.ApartmentState.STA
- Build your host application, and then run your host application.
The problem that is mentioned in the "Symptoms" section does not occur.
If you specify the apartment state of a new thread as multithreaded before the thread is started, you must specify the apartment state of the thread as single-threaded instead. To do this, follow these steps:
- If you specify the apartment state of the MyThread thread as multithreaded in the code for your host application, locate the following code:
MyThread.ApartmentState = Threading.ApartmentState.MTA
- Replace the code that you located in the previous step with the following code:
' Specify that the MyThread thread runs in an STA.
MyThread.ApartmentState = Threading.ApartmentState.STA
- Build your host application, and then run your host application.
The problem that is mentioned in the "Symptoms" section does not occur.