Ranorex Thread in a C# Windows Application

Ask general questions here.
darkheart
Posts: 2
Joined: Tue Mar 04, 2008 1:26 am

Ranorex Thread in a C# Windows Application

Post by darkheart » Tue Mar 04, 2008 5:11 am

I have a windows application that's written in C# where I'm using a separate thread to read a large list of values from another window (SysListView32 custom control with 10,000+ elements).

I'm using a loop in the Ranorex thread that looks like the following:

Code: Select all

int listsize = ParentElement.ChildCount;
Element ChildElement;
for (int i = 0; i < listsize; i++)
{
  ChildElement = null;
  do
  {
    ChildElement = ParentElement.GetChild(i);
    Thread.Sleep(32);
  }while (ChildElement == null);
  
  ListTable.Rows.Add(ChildElement.Name,
                     ChildElement.Description);   
}
The loop works fine (except for being very very slow) with one small quirk.
When the main window loses focus, the Ranorex thread stops reading elements until it retains focus.

Can anyone shed some light onto why this is happening and/or provide a work around solution.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Tue Mar 04, 2008 11:11 am

First to the focus problem:
In fact it is true that some controls require focus in order to read their elements. However, I just tried to reproduce that behavior with the windows explorer tree view, but I can't. It seems to be a speciality of the control you use.

Secondly, the speed problem:
Be sure to set the Element.StaticProperties property to true. That should speed up the getting the Name of an element by far.
The other thing is to replace the loop calling GetChild() by the FindChildren method:

Code: Select all

Element[] Children = ParentElement.FindChildren(Role.OutlineItem);
foreach (Element ChildElement in Children)
{
    ListTable.Rows.Add(ChildElement.Name, ChildElement.Description);
}
Perhaps that also solves the focus problem, but I'm not sure of that :?

Regards,
Alex
Ranorex Support Team