Go to Robotic Automation version 22.1 documentation

Updating controls on Windows Forms

When you create automations that update controls on Windows Forms (such as updating the data displayed in a DataGrid or ListBox), be aware of possible threading errors. Microsoft advises that access to Windows forms controls is not inherently thread-safe (see MSDN How to: Make Thread-Safe Calls to Windows Forms Controls). Avoid making a call to a control from a thread (execution path) other than the one that created the control.

For example, a Studio project populates a DataGrid on a Windows form based on data contained in an web application's HTML table (Products table from the Studio training website). The following example shows populating a DataGrid by binding it to a TableView component. The data for the TableView (the TableProvider) is a LookupTable which is populated by iterating through the rows of the HTML table. Note that the event that starts the automation logic is the Created event for the HTML table. The update automation shows a thread-safe way to update the DataGrid.

 

Unsafe Call to Update DataGrid

Automation initiating event runs on the adapter thread (WebAdapter.HTMLTable.Created event) which populates a table provider bound to a WinForm DataGrid.  This causes a cross-thread WinForm call exception.

 

Thread-safe Call to Update DataGrid

Automation initiating event runs on the Windows Control thread (Button.Click event) which populates a table provider bound to the DataGrid on the same Windows form.

 

 


Privacy | Trademarks | Terms of Use | Feedback

Updated: 01 July 2024

© 2016 - 2024 Pegasystems Inc.  Cambridge, MA All rights reserved.

 

OpenSpan data classification label