Instead of setting the apartment state of the separate thread (which is some cases makes perfect sense, because you may need to use one apartment state in one thread (say, main one) and different in some other thread, to use some API requiring certain apartment state), it doesn't look like you need it in your case.
Instead, you could simply set STA thread for your main thread at the point where you have your entry point method:
using System;
[STAThread]
static void Main( ) {
}
This way may look not universal enough. It is not. It's just fit most of the cases. Let's see: a console application can start with either
STAThread
or
MTAThread
, same thing with
System.Windows.Forms
, but WPF requires
[STAThread]
. In other words, in most cases, you cannot go wrong with
STAThread
. And only in some special cases you many need both.
—SA