WPF using MVVM with WCF in an asynchronous wait pattern

I am creating a WPF application that uses MVVM as a template along with the WCF backend. My user interface should always be responsive, and for some controls, data can load up to 10 seconds.

The following code works well and is inside my view model, where ConfigurationsForInterface is the Observable type associated with my control:

ConfigurationsForInterface = new ObservableCollection<string>() { "Loading..." };      
ConfigurationsForInterface = await GetConfigurationInterfaceXAsync();

A method that works great:

      public async Task<ObservableCollection<string>> GetConfigurationHL7Server5Async()
        {
            ObservableCollection<string> result;

            using (var localClient = new ManagerListenerClient(Globals.ChannelBinding, Globals.EndpointAddress))
            {               
                result = await  localClient.GetConfigurationsAsync("interfacex");
            }

            return result;
        }

A method that freezes my user interface as I reuse a service client already open in other areas of the application as I set the context for the service (user):

  public async Task<ObservableCollection<string>> GetConfigurationHL7Server5Async()
    {
        ObservableCollection<string> result;

        result = await Globals.Client.GetConfigurationsAsync("interfacex"); 

        return result;
    }

, WCF- - , . , .

- , WCF, , , viewmodel

+4
1

@Rowbear .

WsHttpBinding NetTCPBinding, . NetTCPBinding.

, - . WsHttpBinding.

! .

0

Source: https://habr.com/ru/post/1666012/


All Articles