none
e.UserState not available in Completed event in the c# app RRS feed

  • Question

  • I am trying to implement a callback for the method I defined in the ModelLib.cs and it has the following code.But e.UserSTate is not available.IS there a way we can replace it with something.

    public class TrackingDetailsModel { public void GetCurrentLocation() { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);   watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(this.watcher_PositionChanged);      

    } } private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { Action<LocationInfo> target = (Action<LocationInfo>)e.UserState;//user state here is not recognized.. }

    The LocaionInfo class is defined in UtilLib.cs like below :

     public class LocationInfo
       { 
        public string Altitude{ get; set; }
        public string Longitude{ get; set; }
        public string Latitude{ get; set; }
       }

    Krrishna


    • Edited by Krrrishna Tuesday, October 15, 2013 4:03 PM
    Tuesday, October 15, 2013 3:26 PM

Answers

  • There is no UserState property in this definition and therefore it cannot be called.  The only properties exposed by the args is Position.  However Position, which is generic, may have the property so look at that definition.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    • Proposed as answer by Jason Dot Wang Friday, October 18, 2013 8:14 AM
    • Marked as answer by Jason Dot Wang Thursday, October 24, 2013 2:52 AM
    Wednesday, October 16, 2013 2:11 PM
    Moderator

All replies

  • You are passing GeoPositionChangedEventArgs<GeoCoordinate> to the handler.    That is your code so you need to make sure that your UserState property is being exposed publicly from it.  It would have to be something like this

    public class GeoPositionChangedEventArgs<T> : EventArgs
    {
       public someType UserState { get; private set; }
       ...
    }

    If you post the definition we might be able to help you better.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    Tuesday, October 15, 2013 9:42 PM
    Moderator
  • namespace System.Device.Location
    {
        // Summary:
        //     Provides data for System.Device.Location.GeoCoordinateWatcher.PositionChanged
        //     events.
        //
        // Type parameters:
        //   T:
        //     The type of the location data in the System.Device.Location.GeoPosition<T>.Location
        //     property of this event's System.Device.Location.GeoPositionChangedEventArgs<T>.Position
        //     property.
        public class GeoPositionChangedEventArgs<T> : EventArgs
        {
            // Summary:
            //     Initializes a new instance of the System.Device.Location.GeoPositionChangedEventArgs<T>
            //     class.
            //
            // Parameters:
            //   position:
            //     A System.Device.Location.GeoPosition<T> object containing the location and
            //     time stamp data for the event.
            public GeoPositionChangedEventArgs(GeoPosition<T> position);
    
            // Summary:
            //     A System.Device.Location.GeoPosition<T> object containing the location and
            //     time stamp data for the System.Device.Location.GeoCoordinateWatcher.PositionChanged
            //     event.
            //
            // Returns:
            //     Type: System.Device.Location.GeoPosition<T>.
            public GeoPosition<T> Position { get; }
        }
    }

    That's what I see in its definition..


    Krrishna

    Wednesday, October 16, 2013 3:10 AM
  • There is no UserState property in this definition and therefore it cannot be called.  The only properties exposed by the args is Position.  However Position, which is generic, may have the property so look at that definition.

    Michael Taylor
    http://msmvps.com/blogs/p3net

    • Proposed as answer by Jason Dot Wang Friday, October 18, 2013 8:14 AM
    • Marked as answer by Jason Dot Wang Thursday, October 24, 2013 2:52 AM
    Wednesday, October 16, 2013 2:11 PM
    Moderator