Update TextBox on a form in a QueuedTask

256
2
Jump to solution
05-21-2021 10:32 AM
BrianBulla
Regular Contributor

Hi,

Is it possible to update Windows Form objects (ie. TextBox, ComboBox, etc) while in a QueuedTask?  I keep getting the "wrong thread" exception error.

What I am doing is working with a selected feature, to populate fields on a form.  Is there a recommended way of dealing with this?

Thanks,

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Brian,

 You have to make any updates to the UI from the UI thread.   There is a sample utility function in this community sample called RunOnUIThread that allows you to switch threads and run an Action on the UI thread.  arcgis-pro-sdk-community-samples/BookmarkDockpaneViewModel.cs at 44183d0d5a9bc5da6fb8b9229211cc707dd...

Depending on your use case you can also use the Dispatcher class as shown here:

arcgis-pro-sdk-community-samples/Module1.cs at 44183d0d5a9bc5da6fb8b9229211cc707dd2b874 · Esri/arcgi...

You mentioned 'Windows Form' objects which would exclude the use of synchronization patterns that are exclusive to WPF like BindingOperations.EnableCollectionSynchronization

View solution in original post

2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Brian,

 You have to make any updates to the UI from the UI thread.   There is a sample utility function in this community sample called RunOnUIThread that allows you to switch threads and run an Action on the UI thread.  arcgis-pro-sdk-community-samples/BookmarkDockpaneViewModel.cs at 44183d0d5a9bc5da6fb8b9229211cc707dd...

Depending on your use case you can also use the Dispatcher class as shown here:

arcgis-pro-sdk-community-samples/Module1.cs at 44183d0d5a9bc5da6fb8b9229211cc707dd2b874 · Esri/arcgi...

You mentioned 'Windows Form' objects which would exclude the use of synchronization patterns that are exclusive to WPF like BindingOperations.EnableCollectionSynchronization

BrianBulla
Regular Contributor

Thanks Wolfgang.  I'll check out those links.

 

0 Kudos