0

The error Im getting : The calling thread must be STA, because many UI components require this.

So I have an android application which generates a bill of materials on the server side. Therefore a new UI has to be generated for the bill of materials. When I try to add a product to the BOM..this is the error I am getting. How do I go about it. An solution allowing me to host the service the android application is using is already running. The BOM application is a part of this solution.

Sana
  • 147
  • 1
  • 1
  • 13
  • 1
    possible duplicate of [The calling thread must be STA, because many UI components require this in WPF](http://stackoverflow.com/questions/4183622/the-calling-thread-must-be-sta-because-many-ui-components-require-this-in-wpf) – Robaticus May 24 '12 at 12:24

1 Answers1

1

When you create a new thread in your application, set its apartement state like in the code below before you start it:

            Thread myThread = new Thread(() =>
            {

            });

            myThread.SetApartmentState(ApartmentState.STA);
            myThread.Start();

If you do not create new Threads like this you may have to declare you "main" or "startup" -method with an [STAThread] - attribute. See here: Why does WPF require a STAThread attribute to be applied to the Main method?

Community
  • 1
  • 1
schoola
  • 704
  • 6
  • 12