Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

GeoCoordinateWatcher.TryStart Method

Initiates the acquisition of data from the current location provider. This method returns synchronously.

Namespace:  System.Device.Location
Assembly:  System.Device (in System.Device.dll)

public bool TryStart(
	bool suppressPermissionPrompt,
	TimeSpan timeout
)

Parameters

suppressPermissionPrompt
Type: System.Boolean

true to suppress the permission dialog box; false to display the permission dialog box.

timeout
Type: System.TimeSpan

Time in milliseconds to wait for the location provider to start before timing out.

Return Value

Type: System.Boolean
true if data acquisition is started within the time period specified by timeout; otherwise, false.

Implements

IGeoPositionWatcher<T>.TryStart(Boolean, TimeSpan)

This method blocks execution of the calling thread during the time period specified by timeout. Use caution when calling TryStart from the user interface thread of your application.

The following example demonstrates how to call TryStart.

using System;
using System.Device.Location;

namespace GetLocationProperty
{
    class Program
    {
        static void Main(string[] args)
        {
            GetLocationProperty();
        }

        static void GetLocationProperty()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

            // Do not suppress prompt, and wait 1000 milliseconds to start.
            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));

            GeoCoordinate coord = watcher.Position.Location;

            if (coord.IsUnknown != true)
            {
                Console.WriteLine("Lat: {0}, Long: {1}",
                    coord.Latitude,
                    coord.Longitude);
            }
            else
            {
                Console.WriteLine("Unknown latitude and longitude.");
            }
        }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft