Click or drag to resize

LocalServiceStatusChanged Event

Occurs when Status of this local service has changed.

Namespace:  Esri.ArcGISRuntime.LocalServices
Assembly:  Esri.ArcGISRuntime.LocalServices (in Esri.ArcGISRuntime.LocalServices.dll) Version:
public event EventHandler<StatusChangedEventArgs> StatusChanged


Type: SystemEventHandlerStatusChangedEventArgs


Example Name: LocalServerFeatureLayer

Start a local feature service and display its features in a map.

Code example screen shot.

// Copyright 2018 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.LocalServices;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.IO;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.LocalServerFeatureLayer
        "Local Server feature layer",
        "Local Server",
        "This sample demonstrates how to display a Feature Layer service by a Local Server feature service.",
        "Sample data is downloaded automatically from ArcGIS Online by the sample viewer.")]
    public partial class LocalServerFeatureLayer
        // Hold a reference to the local feature service; the ServiceFeatureTable will be loaded from this service
        private LocalFeatureService _localFeatureService;

        public LocalServerFeatureLayer()

            // Create the UI, setup the control references and execute initialization

        private async void Initialize()
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateStreetsWithReliefVector());

                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started)
                    await LocalServer.Instance.StopAsync();

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath = Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            catch (Exception ex)
                MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in Message: {0}", ex.Message), "Local Server failed to start");

            // Load the sample data and get the path
            string myfeatureServicePath = GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
                await _localFeatureService.StartAsync();
            catch (Exception ex)
                MessageBox.Show(ex.Message, "The feature service failed to load");

        private async void _localFeatureService_StatusChanged(object sender, StatusChangedEventArgs e)
            // Load the map from the service once ready
            if (e.Status == LocalServerStatus.Started)
                // Get the path to the first layer - the local feature service url + layer ID
                string layerUrl = _localFeatureService.Url + "/0";

                // Create the ServiceFeatureTable
                ServiceFeatureTable myFeatureTable = new ServiceFeatureTable(new Uri(layerUrl));

                // Create the Feature Layer from the table
                FeatureLayer myFeatureLayer = new FeatureLayer(myFeatureTable);

                // Add the layer to the map

                    // Wait for the layer to load
                    await myFeatureLayer.LoadAsync();

                    // Set the viewpoint on the MapView to show the layer data
                    await MyMapView.SetViewpointGeometryAsync(myFeatureLayer.FullExtent, 50);
                catch (Exception ex)
                    MessageBox.Show(ex.ToString(), "Error");

        private static string GetFeatureLayerPath()
            return DataManager.GetDataFolder("4e94fec734434d1288e6ebe36c3c461f", "PointsOfInterest.mpk");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.LocalServerFeatureLayer.LocalServerFeatureLayer"
             d:DesignHeight="300" d:DesignWidth="300">
        <esri:MapView x:Name="MyMapView"/>

See Also
Additional Examples
Hyperlink to ExampleDescription
DynamicWorkspaceRasterDynamically add a local raster file to a map using Local Server.
DynamicWorkspaceShapefileDynamically add a local shapefile to a map using Local Server.
LocalServerFeatureLayerStart a local feature service and display its features in a map.
LocalServerGeoprocessingCreate contour lines from local raster data using a local geoprocessing package `.gpk` and the contour geoprocessing tool.
LocalServerServicesDemonstrates how to start and stop the Local Server and start and stop a local map, feature, and geoprocessing service running on the Local Server.