1

I read a lot online about how bad awaiting a void method is. I just wanted to know what are the possible consequence(s)? Could it slow down my application over time if I am getting data from another machine over a network?(I use Task.Run and it works fine but just is there an alternative?)

CallTheCurrentWFControls() load data from a json file on my local machine but my async method gets only a list index over the network.

I find my self using allot of async voids how can I break this pattern? Is there a part of the MVVM pattern I am missing(That handles async methods on selection changed on a bonded list box)?

MainWindow _MainWindow = Application.Current.MainWindow as MainWindow;

private ObservableCollection<WFControl> _CurrentFilteredControls;
public ObservableCollection<WFControl> CurrentFilteredControls
{
    get { return _CurrentFilteredControls; }
    set
    {
        if (_CurrentFilteredControls != value)
        {
            _CurrentFilteredControls = value;
            OnPropertyChanged();
        }
    }
}

private WFControl _SelectedCurrentFilteredControls;
public WFControl SelectedCurrentFilteredControls
{
    get { return _SelectedCurrentFilteredControls; }
    set
    {
        if (_SelectedCurrentFilteredControls != value)
        {
            _SelectedCurrentFilteredControls = value;
            CallTheCurrentWFControls();
            Task.Run(() => _MainWindow.UpdateIndex());
            OnPropertyChanged();

        }
    }
 }

public async void UpdateIndex()
{
    try
    {
        object o = await GetVentuxIndex(".Index");

    }
    catch (Exception ex)
    {
            LogFileController.WriteCurrentErrorOrWarningToXmlFile(ex.Message, "UpdateIndex");
    }
}

WPF:

<ListBox x:Name="lbx" ItemsSource="{Binding VM.CurrentFilteredControls, Mode=TwoWay}"   ItemContainerStyle="{StaticResource listContainerStyle}"   ItemTemplate="{DynamicResource dtWFC}"  SelectedItem="{Binding VM.SelectedCurrentFilteredControls, Mode=TwoWay}"  HorizontalAlignment="Right" Width="500" Margin="0,102,140,0" Height="338" VerticalAlignment="Top" Grid.Column="3" BorderThickness="4" BorderBrush="Black" />
Dev
  • 1,780
  • 3
  • 18
  • 46
  • Reference [Async/Await - Best Practices in Asynchronous Programming](https://msdn.microsoft.com/en-us/magazine/jj991977.aspx) – Nkosi Feb 04 '18 at 14:58
  • I suggest you to read [Async Programming : Patterns for Asynchronous MVVM Applications: Data Binding](https://msdn.microsoft.com/en-us/magazine/dn605875.aspx), [Async Programming : Patterns for Asynchronous MVVM Applications: Commands](https://msdn.microsoft.com/en-us/magazine/dn630647.aspx) and [this](https://stackoverflow.com/questions/48212998/how-to-call-an-async-method-from-a-property-setter/48217792#48217792) question. – YuvShap Feb 04 '18 at 22:12

0 Answers0