0

I want to pass three extra parameters to the event :

geocodeService.GeocodeCompleted += new EventHandler<GeocodeService.GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);

The parameters are

  • int id
  • string color
  • double heading

    private void Geocode(string strAddress, int waypointIndex, int id, string color, double heading)
    {
    
    
        // Create the service variable and set the callback method using the GeocodeCompleted property.
        GeocodeService.GeocodeServiceClient geocodeService = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
    
        // NEED TO PASS id, color, heading TO THIS EVENT HANDLER
        geocodeService.GeocodeCompleted += new EventHandler<GeocodeService.GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
    
        GeocodeService.GeocodeRequest geocodeRequest = new GeocodeService.GeocodeRequest();
        geocodeRequest.Credentials = new Credentials();
        geocodeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)BingMap.CredentialsProvider).ApplicationId;
        geocodeRequest.Query = strAddress;
        geocodeService.GeocodeAsync(geocodeRequest, waypointIndex);
    }
    
    
    private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
    {
        GeocodeResult result = null;
    
        if (e.Result.Results.Count > 0)
        {
            result = e.Result.Results[0];
            if (result != null)
            {
                // this.ShowMarker(result);
                this.ShowShip(result);
    
    
            }
        }
    
    }
    
LukeHennerley
  • 6,344
  • 1
  • 32
  • 50
Solo
  • 569
  • 1
  • 7
  • 27

2 Answers2

0

you can extend GeocodeService.GeocodeServiceClient adding those properties and then use the sender argument in the event method geocodeService_GeocodeCompleted:

var service = (GeocodeService.GeocodeServiceClient) sender;

The quick and dirty(IMHO) version is to use lambda expression:

Pass parameter to EventHandler

Community
  • 1
  • 1
giammin
  • 18,620
  • 8
  • 71
  • 89
0

It looks like GeocodeCompletedEventArgs extends AsyncCompletedEventArgs. AsyncCompletedEventArgs has the property UserState which can be used to store state information for asynchronous events. This state is usually passed as a parameter to the method that raises the event.

See this question for more information: Bing GeocodeService userState usage as custom additional parameter

Community
  • 1
  • 1
qxn
  • 17,162
  • 3
  • 49
  • 72
  • i don't agree with your answer because UserState should be used to unique identify the asynchronous task and not to pass data: http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.userstate.aspx – giammin Feb 01 '13 at 13:59