Problem with delegate and C # dispatcher

I get this error when trying:

The expected name of the ERROR method.

How can I do to fix the problem

delegate void DelegateFillList(DeliveryDoc[] deliveryDocs); private void FillListViewAssignment(DeliveryDoc[] docs) { if(lvMyAssignments.Dispatcher.CheckAccess()) { lvMyAssignments.ItemsSource = docs; lvAllOngoingAssignments.ItemsSource = docs; if(m_tempDeliveryDocs != null) { txtblockHandOverCount.Text = m_tempDeliveryDocs.Length.ToString(); } } else { lvMyAssignments.Dispatcher.BeginInvoke( new DelegateFillList(FillListViewAssignment(docs)), null); } } 
+4
source share
4 answers

This is the problem:

 new DelegateFillList(FillListViewAssignment(docs) 

You cannot create a delegate this way. You need to provide a group of methods, which is just the name of the method:

  lvMyAssignments.Dispatcher.BeginInvoke (new DelegateFillList(FillListViewAssignment), new object[]{docs}); 

Alternatively, you can do this in two statements:

 DelegateFillList fillList = FillListViewAssignment; lvMyAssignments.Dispatcher.BeginInvoke(fillList, new object[]{docs}); 

The reason for the extra wrapping array is that you have only one argument, which is an array - you don't want it to try to interpret this as a bunch of different arguments.

+4
source

Change the last line to:

  lvMyAssignments.Dispatcher.BeginInvoke( new DelegateFillList(FillListViewAssignment), docs); 
+2
source

I think you need to specify the arguments in the else part.

Try the following:

 lvMyAssignments.Dispatcher.BeginInvoke(new DelegateFillList(FillListViewAssignment), new object[]{docs}); 

EDITED - Enabled new object[]{docs} . Thanks John and Hank

+1
source

This line:

 lvMyAssignments.Dispatcher.BeginInvoke( new DelegateFillList(FillListViewAssignment(docs)), null); 

Note that you are passing the method call to the delegate, not the method name. Change it as follows:

 lvMyAssignments.Dispatcher.BeginInvoke( new DelegateFillList(FillListViewAssignment), null); ^ | +- removed (docs) 
0
source

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


All Articles