none
How to pass parameter into the asynchronous xx_completed procedure ? RRS feed

  • Question



  • Hi guys, I wish someone can help me, I cant find anything on the web about this issue;

    I am trying to do asynchronous call to the WCF.

    Here is the example code:

    private void DoTotalRevenue(string objectToPopulate)
    {
       _ppws.GetTotalRevenueCompleted += new EventHandler<GetTotalRevenueCompletedEventArgs>(DoTotalRevenue_Completed);
       _ppws.GetTotalRevenueAsync();
    }

    private void DoTotalRevenue_Completed(object sender, GetTotalRevenueCompletedEventArgs e)
    {
      //I need to get that string objectToPopulate into here.
    }

    My Question is how can I pass that variable string objectToPopulate in DoTotalRevenue to the DoTotalRevenue_Completed

     

    Thank you very much.

    Tempolong

     
    Sunday, April 11, 2010 10:58 PM

Answers

  • private void DoTotalRevenue(string objectToPopulate)
    {
       _ppws.GetTotalRevenueCompleted += new EventHandler<GetTotalRevenueCompletedEventArgs>(DoTotalRevenue_Completed);
       _ppws.GetTotalRevenueAsync(objectToPopulate);
    }
    
    private void DoTotalRevenue_Completed(object sender, GetTotalRevenueCompletedEventArgs e)
    {
      //I need to get that string objectToPopulate into here.
      string objectToPopulate = (string)e.UserState;
    }
    

    Use the GetTotalRevenueAsync overload that accepts an object parameter called userState. This userState is passed to your event handler in UserState property in GetTotalRevenueCompletedEventArgs.

     

    Monday, April 12, 2010 12:56 AM

All replies

  • private void DoTotalRevenue(string objectToPopulate)
    {
       _ppws.GetTotalRevenueCompleted += new EventHandler<GetTotalRevenueCompletedEventArgs>(DoTotalRevenue_Completed);
       _ppws.GetTotalRevenueAsync(objectToPopulate);
    }
    
    private void DoTotalRevenue_Completed(object sender, GetTotalRevenueCompletedEventArgs e)
    {
      //I need to get that string objectToPopulate into here.
      string objectToPopulate = (string)e.UserState;
    }
    

    Use the GetTotalRevenueAsync overload that accepts an object parameter called userState. This userState is passed to your event handler in UserState property in GetTotalRevenueCompletedEventArgs.

     

    Monday, April 12, 2010 12:56 AM
  • Thanks, I'll give it a try.
    Monday, April 12, 2010 1:01 AM