Select to view content in your preferred language

update a Label-Content from values found in a QueuedTask

444
2
Jump to solution
01-16-2024 01:28 AM
ChristianPagel1
New Contributor II

Hi, I want to update a Label-Content from values found in a QueuedTask.
How can I access the GUI?

ArcGISpro 2.9, VS2019, .NET 4.8

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
 
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using System.Windows.Threading;
 
namespace AttributeValues
{
    /// <summary>
    /// Interaction logic for ProWindow1.xaml
    /// </summary>
    public partial class ProWindow1 : ArcGIS.Desktop.Framework.Controls.ProWindow
    {
        public ProWindow1()
        {
            InitializeComponent();
        }
 
        private void Button_1_Click(object sender, RoutedEventArgs e)
        {
            var map = MapView.Active?.Map;
            FeatureLayer layer = map.FindLayers("streets").FirstOrDefault() as FeatureLayer;
            getNames(layer);
        }
 
 
 
        private static async Task getNames(FeatureLayer layer)
        {
 
            QueuedTask.Run(() =>
            {
                try
                {
                    string sWhereClause = "42 = 42";
                    string sPostfixClause = "ORDER BY name";
                    string sSubFields = "name";
 
                    QueryFilter queryFilter = new QueryFilter();
                    queryFilter.WhereClause = sWhereClause;
                    queryFilter.PostfixClause = sPostfixClause;
                    queryFilter.SubFields = sSubFields;
                    RowCursor rows = layer.Search(queryFilter);
                    while (rows.MoveNext())
                    {
                        var curRow = rows.Current;
                        string sName = curRow.GetOriginalValue(curRow.FindField("name")).ToString();
                        // Write sName to Label_1 in ProWindow1 to see the progress!!! 
                        // DO SOMETHING WITH THE STREET ...
                        System.Diagnostics.Debug.Print(sName);
                    } // while
                    return true;
                } // try
                catch (Exception exc) { System.Windows.MessageBox.Show(exc.Message); return false; }
            }).Wait();
        } 
    }
}
 
 

 

 

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Look at the question .

Main idea would be to switch to GUI thread and set Label_1 Content property:

            Application.Current.Dispatcher.Invoke(() =>
            {
                Label_1.Content = "some text";
            });

  

View solution in original post

2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Look at the question .

Main idea would be to switch to GUI thread and set Label_1 Content property:

            Application.Current.Dispatcher.Invoke(() =>
            {
                Label_1.Content = "some text";
            });

  

ChristianPagel1
New Contributor II

Hi, thank you for your response. I will try ...

0 Kudos