WPF Thread STA problem

When do use Wpf application  is thread  having  "The calling thread must be STA, because many UI components require this"

Sample Code:

Thread thrTest= new Thread(new ThreadStart(YourFunctionName));
           thrTest.Start();

build this code not error but runtime "The calling thread must be STA, because many UI components require this"

This Code:

Thread thrTest= new Thread(new ThreadStart(YourFunctionName));
           thrTest.SetApartmentState(ApartmentState.STA);
           thrTest.Start();

build and no error :)

Tags:

Leave a Reply