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

  • SEARCH
  • Home
  • 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 9254751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:59+00:00 2026-06-18T11:32:59+00:00

My WPF application with the MVVM pattern shall basically perform the following: Button view

  • 0

My WPF application with the MVVM pattern shall basically perform the following:

  • Button view binds to a command in the view model. –> Check!
  • Command in view model asynchronously queries a webservice for a list of CProject objects for putting it into a ProjectList property. –> Check!

This looks like this…

Command in the view model:

proxy = new SomeService();
proxy.GetProjectList(GetProjectListCallback, username, password);

Callback in the view model:

private void GetProjectListCallback(object sender, GetProjectListCompletedEventArgs e) {
  this.ProjectList = e.Result;
}

SomeService implements an interface ISomeService.

public void GetProjectList(EventHandler<GetProjectListCompletedEventArgs> callback, string username, string password) {
  service.GetProjectListCompleted += callback;
  service.GetProjectListAsync(username, password);
}

So far this works fine. However I feel that I would like to move this callback to the service itself so that the view model only calls something like:

proxy = new SomeService();
this.ProjectList = proxy.GetProjectList(username, password);

But when moving the callback to the service how could it return e.Result to the calling view model? Or would using a Task a better idea?

  • 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-06-18T11:33:00+00:00Added an answer on June 18, 2026 at 11:33 am

    The easiest way is to re-create your WCF service proxy with VS2012. This will change your asynchronous method signatures to be something like:

    Task<MyProjectList> GetProjectListAsync(string username, string password);
    

    and your command becomes:

    proxy = new SomeService();
    this.ProjectList = await proxy.GetProjectListAsync(username, password);
    

    If you don’t want to re-create your WCF service proxy (it will update all your method signatures), then you can wrap the Begin*/End* methods as such:

    public static Task<MyProjectList> GetProjectListTaskAsync(this SomeService @this, string username, string password)
    {
      return Task<MyProjectList>.Factory.FromAsync(@this.BeginGetProjectList, @this.EndProjectList, username, password, null);
    }
    

    I have a full example of this kind of wrapping on my blog.

    or the existing *Async/*Completed members as such:

    public static Task<MyProjectList> GetProjectListTaskAsync(this SomeService @this, string username, string password)
    {
      var tcs = new TaskCompletionSource<MyProjectList>();
      EventHandler<GetProjectListCompletedEventArgs> callback = null;
      callback = args =>
      {
        @this.GetProjectListCompleted -= callback;
        if (args.Cancelled) tcs.TrySetCanceled();
        else if (args.Error != null) tcs.TrySetException(args.Error);
        else tcs.TrySetResult(args.Result);
      };
      @this.GetProjectListCompleted += callback;
      @this.GetProjectListAsync(username, password);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a WPF application using MVVM (Model-View-ViewModel) pattern and I'd like
My WPF application is structured using the MVVM pattern. The ViewModels will communicate asynchronously
I'm prototyping a WPF application with the MVVM pattern. Following an answer to this
I have a wpf application in mvvm pattern. In main view, I have few
I'm writing a WPF application using the MVVM pattern, based on the following article:
In a WPF application following MVVM pattern I have a Customer class which has
I'm implementing a WPF application using the MVVM pattern. The application is basically a
I'm prototyping a WPF application making use of the MVVM pattern. The application shall
I've got a WPF application which uses the MVVM pattern throughout, no code-behind, the
I've an WPF application where tried to implement MVVM pattern and Prism 2. I

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.