IGeoPositionWatcher <GeoPosition> .PositionChanged does not start, but GeoCoordinateWatcher.PositionChanged

I am trying to write an application that controls the location of a computer using the .net 4.0 System.Device.Location namespace. However, I found that the GeoCoordinateWatcher.PositionChanged event is fired only when registering with the event in the class, and not when using the interface that it implements.

Here is the working version of the code:

using (GeoCoordinateWatcher geoCoordinateWatcher = new GeoCoordinateWatcher())
{
    geoCoordinateWatcher.PositionChanged += (sender, args) => Console.WriteLine(args.Position);
    geoCoordinateWatcher.Start();

    Thread.Sleep(2000);
}

This displays the position object as I expected. When I change the code to this:

using (GeoCoordinateWatcher geoCoordinateWatcher = new GeoCoordinateWatcher())
{
    IGeoPositionWatcher<GeoCoordinate> positionWatcher = geoCoordinateWatcher;
    positionWatcher.PositionChanged += (sender, args) => Console.WriteLine(args.Position);
    positionWatcher.Start();

    Thread.Sleep(2000);
}

nothing output. I want to use the interface to make it easier to unit test code.

What am I doing wrong? Is there something subtle I don’t understand about events on common interfaces?

thank

Andy

EDIT:

, ​​ Microsoft. System.Device.dll .net- , GeoCoordinateWatcher 2 PositionChanged. - PositionChanged, - IGeoPositionWatcher.PositionChanged.

, , .

, GeoCoordinateWatcher PositionChanged:

public class MyGeoCoordinateWatcher : GeoCoordinateWatcher, IGeoPositionWatcher<GeoCoordinate>
{
    event EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>> IGeoPositionWatcher<GeoCoordinate>.PositionChanged
    {
        add { base.PositionChanged += value; }
        remove { base.PositionChanged -= value; }
    }
}

, MyGeoCoordinateWatcher, .

- ?

EDIT:

Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/613235/igeopositionwatcher-geocoordinate-positionchanged-event-does-not-fire-on-geocoordinatewatcher-class

+3
2

, . m_positionChanged. PositionChanged PositionChanged.

, , . , , . - connect.microsoft.com. , .

+1

-, . Microsoft , .

0

Source: https://habr.com/ru/post/1769316/


All Articles