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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:30:15+00:00 2026-05-20T09:30:15+00:00

public class AllViewModel { private List<Settings> SettingsList; public ViewAgendaAllViewModel() { client.SupplierListWithSettings(GetSupplierListWithSettings_Completed) } public void

  • 0
public class AllViewModel 
{

    private List<Settings> SettingsList;

    public ViewAgendaAllViewModel()
    {
        client.SupplierListWithSettings(GetSupplierListWithSettings_Completed)
    }

    public void GetSupplierListWithSettings_Completed(object sender, Supplier_GetListWithSettingsCompletedEventArgs e)
    {

        if (e.Error == null)
        {
            if (e.Result != null)
            {
               SettingsList = new List<Settings>(); 
                foreach (VCareSupplierDto obj in e.Result)
                {
                    SettingsList.Add(obj);

                }
            }

        }
    }
}

Issue: Settinglist propery not getting set because of asynch call.

this is my class i want to synchronus call to ServiceMethod SupplierListWithSettings.

When I will create instance of the AllViewModel it should loaded with setting.

Expected : When i will create instance of AllViewModel it should contain SettingList property.

  • 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-20T09:30:15+00:00Added an answer on May 20, 2026 at 9:30 am

    Correction: SettingsList is getting set, but it sounds like it’s not set as soon as you would like.

    It sounds like you’re asking for this: when you construct an instance of AllViewModel, you expect the SettingsList property to be fully populated before the AllViewModel constructor returns.

    While this can be done, there are many reasons why this is probably not a good idea and a dubious design requirement. Making the network call into a synchronous call will block the calling thread (usually, your UI thread) for as long as it takes for the network request to complete, which could be 20 to 30 seconds. Do you really want your application UI to freeze for 30 seconds? Your users are likely to assume your program has crashed or “locked up” and will shut down the program without even realizing that it isn’t dead.

    Nevertheless, here’s how to do it: You can convert the asynchronous call into a synchronous call using something like this (untested) using the .NET 4.0 Task Parallel Library (TPL):

    public AllViewModel()
    {
        var task = Task<List<Settings>>.Factory.StartNew(() =>
                         client.SupplierListWithSettings((s,e) => 
                         {
                             if (e.Error == null && e.Result != null)
                             {
                                 var list = new List<Settings>(); 
                                 foreach (VCareSupplierDto obj in e.Result)
                                 {
                                     list.Add(obj);
                                 }
                                 task.SetResult(list);
                             }
                         }));
        this.SettingsList = task.Result;
    }
    

    Again, this is not a good idea. It would be a much better exercise for you to look at what portions of your code are assuming the SettingsList property is populated immediately after the object is constructed and change those dependencies to do something like listen for changes to the SettingsList property and do their work as soon as SettingsList is actually populated asynchronously.

    Try to go with the asynchronous flow instead of fighting against it.

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

Sidebar

Related Questions

public class MyClass { public int Age; public int ID; } public void MyMethod()
public class Test { public static void main(String[] args) { } } class Outer
public class Item { ... } public class Order { public List<Item> Items ...
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
In the following snippet: public class a { public void otherMethod(){} public void doStuff(String
public class Address { public string ZipCode {get; set;} } public class Customer {
public class CovariantTest { public A getObj() { return new A(); } public static
I have class A: public class ClassA<T> Class B derives from A: public class

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.