Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:41:27+00:00 2026-05-27T15:41:27+00:00

I am learning about MVVM so I can support an application that my predecessor

  • 0

I am learning about MVVM so I can support an application that my predecessor developed. I came across this article which has been helpful.

There is a piece of the code in the article that I don’t understand and have been trying to figure out:

_ServiceAgent.GetPeople((s,e) => this.People = e.Result);

Here is the explanation that the author gives:

a call to GetPeople is made which invokes a method on the service agent and
passes a callback delegate. The WCF service is then called by the
service agent and the results are assigned to the People property.

So I understand that

(s,e) => this.People = e.Result

is a callback delegate and that the result of the function is placed into this.People. But I’m not understanding the “(s,e)” thing and generally am having a hard time grasping the syntax.

Would you mind explaining?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:41:28+00:00Added an answer on May 27, 2026 at 3:41 pm

    Effectively what is happening is:

    1) The ViewModel is given an instance to IServiceAgent
    2) The ViewModel is going to fetch and send data with the IServiceAgent. The viewmodel doesn’t know how to fetch the data, but tells the serviceagent to get it.
    3) The IServiceAgent is not meant to be aware of the ViewModel or how to assign to it.

    This is where your question kicks in. What is the delegate doing, and why does it need (s,e).

    The (s,e) => {} is effectively a way of saying this:
    
    void anonymousMethod(Object s, EventArgs e){};
    

    Why is this done?

    The answer is because you want the IServiceAgent to update the viewModel, but to not have a reference to the ViewModel. How can that be done. Well it could be done using a normal method with a return type. But in this case the example article you have used wants to return its value asyncronously. This can be done by a tradtional method, but it would block your viewmodel. Effectivelly what you are implementing is an like event. The delegate is the contract for the event. So whoever implements the event has to conform to the contract that the delegate provides, for example:

    textbox.Click += (s,e) => {((TextBox)s).Text = "Ive been clicked!"};
    

    -OR-

    textbox.Click += new ClickHandler(myClickHandler);
    
    void myClickHandler(Object sender, EventArgs args){}
    

    -OR-

    textbox.Click += myClickHandler;
    
    void myClickHandler(Object sender, EventArgs args){}
    

    Those all conform to the contract specified by the a click event (which is defined by the events delegate).

    If you compare that to what is defined in the textbox class, it would look something like:

    Class TextBox{      
         event ClickEventHandler Click;    
         delegate ClickEventHandler (Object sender, EventArgs args);   
    }
    

    That therefore means that to implement the textbox click event you have to supply a method that has two inputs of Object sender, EventArgs a and has a void return type. This method can have any name.

    The lambdas used in your question are delgates. Delegates are used to establish method contracts. Your lambda abides by the contract so it is valid. What (s,e) means is up to the delegate of the contract you are abiding by which is:

    EventHandler<GetPeopleCompletedEventArgs> callback
    

    which I belive will generate something like:

    (Object Sender, GetPeopleCompletedEventArgs args) <-------> (s,e)
    

    This might seem a bit crazy to understand why its so hard to see what s and e are, but intellisense should (it works for me with resharper) show the types of s,e. The syntax of (s,e) is very common and the first one will almost always be the same as the .net events being (Object,EventArgs)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In learning about Web Deploy I came across some netsh.exe commands that talk about
For fun I'm learning about graph theory and I came across this problem. Given
I learning about writing my own interfaces and came across the MSDN article Interfaces
I'm learning about using Caliburn.Micro as a MVVM framework for a WPF application. In
Just learning about mercurial's --style and --template options that can be used on hg
Learning about OAuth, I came across a big question. How to call a JavaScript
I have been learning about the basics of C# but haven't come across a
I've recently began learning about QThreads and I've a program which runs a 4
I'm just learning about SproutCore now, seems great. But I can't find a good
Im learning about oauth and i have my application setup and im able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.