An attempt was made to change the apartment state of the thread to %1$s, but it has already been set to %2$s. When creating ...

An attempt was made to change the apartment state of the thread to %1$s, but it has already been set to %2$s. When creating a new thread the apartment state shouldbe set before the thread is started. For the main thread of the application, the apartmentstate can be set by specifying either [STAThreadAttribute] or [MTAThreadAttribute] on themain method of the application. If the application really needs to attempt to set the apartment state on a running thread, Thread.TrySetApartmentState should be used and the return value should be consulted to determine if the operation was successful. Note that Thread.TrySetApartmentState will not fire the InvalidApartmentStateChange MDA.