I have a WPF application that has a MyDataGrid. It has a handler for the MyDataGrid_Loaded event. In this handler, I do some actions, such as MyDataGrid.Items.Refresh() . To reduce the delay in loading the datagrid, I declared a delegate and update the datagrid in it, and I pass it to MyDataGrid by the link:

 public partial class MainWindow { public delegate void DataGridUpdateDelegate(ref DataGrid datagrid); public static void DataGridUpdate(ref DataGrid datagrid) { datagrid.Items.Refresh(); } private void MyDataGrid_Loaded(object sender, RoutedEventArgs e) { ... DataGridUpdateDelegate _tmpDelegate = DataGridUpdate; _tmpDelegate.BeginInvoke(ref MyDataGrid, nul, null); } } 

But MyDataGrid not updated, although the delegate fulfills.

What is wrong here?

  • And what type of variable MyDataGrid should we guess ourselves? - VladD
  • @VladD well what type it is clear. most likely this is the name of the control. Just wondering how this is compiled without specifying the type of a variable after the word ref in the delegate's declaration and method - vitidev
  • Pardon her datagrid type - avm
  • one
    Just ask, interesting. Why is ref used in this case? If my memory does not change me, it is needed only if it is necessary to change the link itself, and not the data on it (this is possible without ref). - DanielOlivo
  • one
    I don't understand why transferring it by ref. and BeginInvoke, as far as I remember from ancient times, asynchrony is performed in pool threads, not UI, that is, it must swear that the stream is not in the stream, but the exception is swallowed - vitidev

1 answer 1

Check which thread is working with the DataGrid element. In the WPF GUI, there can be only one thread controlling the main window and it should be the main thread that started the process.