There are 2 questions in my topic:
- 1. Where exactly Appartment State should be set to STA (STAThread applied) for situations where all calls to Ranorex API are made in separate thread?
2. Where can detailed documentation about Appartment State STA that is required for Ranorex API calls be found?
So 1st question is: which threads' Appartment State should be set to STA? Main thread of the application that runs test code OR namely the thread where calls to Ranorex API are executed?
2nd question: Please provide a link to help article that covers all aspects related to STA Apartment State that is required for Ranorex usage? (I have already found many topics that reference STAThread attribute in short - including this user guide article http://www.ranorex.com/support/user-gui ... ation.html - is there any more in detail documentation about relations between Ranorex libraries functionality and parameters of a thread that makes calls to that library?)
I have already noticed that Ranorex functionality works OK only when [STAThread] attribute is set on Main method only - for the application that makes calls to Ranorex API. For situations when Appartment State is set to STA for the thread where calls to Ranorex API are executed (as in mock-up code below) - then location of controls does not work. Could you please explain the reasons of such behavior?
Code: Select all
namespace Test
{
class Program
{
static void Main(string[] args)
{
Thread automationThread = new Thread(executeAutomation);
automationThread.Start();
// Makes locations of controls not execute successfully
automationThread.SetApartmentState(ApartmentState.STA);
}
private static void executeAutomation
{
// Make calls to Ranorex API
}
}
}
Problem was that Apartment state STA was set for Ranorex thread after thread start (unless some magic interfered me). After setting Apartment State STA before Ranorex thread start location of controls by Ranorex API in separate thread works OK.
Thanks very much for your reply.