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 6179693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:42:53+00:00 2026-05-24T00:42:53+00:00

Let me show the code first. WCF servicecontract function: public List<VenueData> GetVenues() { List<VenueData>

  • 0

Let me show the code first.

WCF servicecontract function:

   public List<VenueData> GetVenues()
    {
        List<VenueData> listOfVenues = new List<VenueData>();

        string connString = @"....";

        DataContext dc = new DataContext(connString);
        Table<VenueData> venues = dc.GetTable<VenueData>();

        listOfVenues = (from v in venues
                       select v).ToList();

        return listOfVenues;
    }

VenueViewModel.cs

public class VenueViewModel : ViewModelBase
{
    private VenueData _venue;
    private ObservableCollection<VenueData> _venues = new ObservableCollection<VenueData>();        

    public VenueData Venue
    {
        get
        {
            return _venue;
        }
        set
        {
            if (_venue != value)
            {
                _venue = value;
                OnNotifyPropertyChanged("Venue");
            }
        }
    }

    public ObservableCollection<VenueData> Venues
    {
        get
        {
            return _venues;
        }
        set
        {
            if (_venues != value)
            {
                _venues = value;
                OnNotifyPropertyChanged("Venues");
            }
        }
    }

    public void GetAllVenues()
    {

        TicketOrderWcfClient toClient = new TicketOrderWcfClient();
        toClient.GetVenuesCompleted += new EventHandler<GetVenuesCompletedEventArgs>(toClient_GetVenuesCompleted);
        toClient.GetVenuesAsync();            
    }

    void toClient_GetVenuesCompleted(object sender, GetVenuesCompletedEventArgs e)
    {
        if (e.Error == null)
            Venues = e.Result;
    }
}

MainPage.xaml(view)

   public MainPage()
    {
        InitializeComponent();
        Loaded += new RoutedEventHandler(MainPage_Loaded);
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        VenueViewModel vvm = new VenueViewModel();
        vvm.GetAllVenues();

        MessageBox.Show(vvm.Venues.Count.ToString());

    }

Well this is most of the code. The problem is that in the MainPage_Loaded event vvm.GetAllVenues() will not populate the Venues ObservableCollection. The MessageBox will show 0. I tested the wcf service is good, also fiddler showed the soap fine. Also if i call the wcf service in the MainPage_Loaded event, then it will work. See below:

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {

        TicketOrderWcfClient toClient = new TicketOrderWcfClient();
        toClient.GetVenuesCompleted += new EventHandler<GetVenuesCompletedEventArgs>(toClient_GetVenuesCompleted);
        toClient.GetVenuesAsync();  
    }


    void toClient_GetVenuesCompleted(object sender, GetVenuesCompletedEventArgs e)
    {
        if(e.Error == null)
        {
            VenueViewModel vvm = new VenueViewModel();
            vvm.Venues = e.Result;
            MessageBox.Show(vvm.Venues.Count.ToString());
        }
    }

This time MessageBox will show 3, which is good because there are 3 records in the db. So it looks like there is a problem between the View and the ViewModel. I suspect i am missing a pretty basic thing here. Also note that i know this is not true MVVM, but i have to accomplish this program this way.
I hope my explanation is clear, thank you for your help.

  • 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-24T00:42:54+00:00Added an answer on May 24, 2026 at 12:42 am

    In your first approach, which does not work, the flow of the code:

    MessageBox.Show(vvm.Venues.Count.ToString());
    

    is not connected with the termination of your asynchronous call of the WCF method! In other word, you show the mbox, but you do not make sure that the asynchronous call has terminated.

    Of course, you had assigned a delegate to GetVenuesCompleted event, but the call of toClient.GetVenuesAsync() is an asynchronous call, which means that when invoked it does not wait for the result (termination). So when you call:

    vvm.GetAllVenues();
    

    Then

    MessageBox.Show(vvm.Venues.Count.ToString());
    

    is invoked faster then your toClient_GetVenuesCompleted delegate.

    Your second approach works because you show the messagebox when the asynchronous method is completed (in your GetVenues callback).

    In my opinion, you can repair it for example by adding a new event GetAllVenuesCompleted in VenueViewModel which will be fired at the end of the toClient_GetVenuesCompleted delegate. In other words, I would pass this event further. Additionally I would add a comment that GetAllVenues is an asynchronous method.

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

Sidebar

Related Questions

Let's first start with a code snippet to explain the issue: = Haml::Engine.new('#bar= yield').render
I have a list of elemnts (let's say 10) and I only show first
First let me show some code. class User has_and_belongs_to_many :roles named_scope :employees, { :conditions
Here's my code: <?php class Test_Class { public function Show() { return Test_Class->Show() function;
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't
I am having difficulties implementing a custom ASP.NET RoleProvider. First off, let me show
my first question here.. :) Let's begin with the code... my page is <form
First, let me show you the struct: struct HPOLY { HPOLY() : m_nWorldIndex(0xFFFFFFFF), m_nPolyIndex(0xFFFFFFFF)
I begin to learn re module. First I'll show the original code: import re
Is there a .NET library/tutorial available that will let me show me how 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.