I was surprised your code did not work, so I've done the following test:
namespace SetSTA {
using System;
using System.Threading;
class Program {
[MTAThread]
static void Main(string[] args) {
Thread mainThread = Thread.CurrentThread;
System.Console.WriteLine(
"Main thread apartment state: {0}",
mainThread.GetApartmentState());
Thread staThread = new Thread( () => {
Thread thisThread = Thread.CurrentThread;
System.Console.WriteLine(
"Custom thread apartment state: {0}",
thisThread.GetApartmentState());
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
System.Console.ReadKey();
}
}
}
This code sample works as expected; this is output:
Main thread apartment state: MTA
Custom thread apartment state: STA
You problem is not reproduced.
At the same time, you try to change the apartment state in exact same way; and your code looks correct.
However, the problem can be somewhere else in your code which is not shown to us. At what moment of time your thread's apartment state is changed back to MTA? Where is the code to indicate that?
In this case, complete code which shows the problem is needed. Can you submit such thing?