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" />