[WPF] Error: Parameter count mismatch (using Dispatcher please note)

Abstract: [C #] Parameter count mismatch (dispatcher)


That generates an Error when using dispatcher.BeginInvoke: Parameter count mismatch

code something like this error occurs


 public void FunA()
 {            
      int[] Array = new int[3] { 0, 1, 2 };
      Dispatcher.BeginInvoke(new FuncDelegate(Function), Array);
 }

 private delegate void FuncDelegate(int[] Array);
 private void Function(int[] Array)
 {
      //something...
 }

Check MSDN

public DispatcherOperation BeginInvoke(
	Delegate method,
	params Object[] args
)

Maybe you'll have a clue, primarily for use ... args parameter this is not the case use

params keyword allows you to specify the method parameter can accept parameters, where the number of parameters is variable. (Sample code can check MSDN good friend XD)

Perhaps the solution is clear ... is to arrary apart, one by one go into ...


int[] Array = new int[3] { 0, 1, 2 };
Dispatcher.BeginInvoke(new FuncDelegate(Function), Array[0], Array[1], Array[2]);

But be smart, use a whole array package object variable Hello (remember to practice in the Function, need to obj and then back int [])


int[] Array = new int[3] { 0, 1, 2 };
object obj = Array;
Dispatcher.BeginInvoke(new FuncDelegate(Function), obj);

Also add ================ =================

C ++ is the past through postMessage / sendMessage to let the UI update

But in your C # can be used to achieve Dispatcher (to be used in C # postMessage also possible, on the introduction of user32.dll)

The Dispatcher.Invoke equivalent sendMessage, Dispatcher.BeginInvoke is equivalent postMessage

Any questions or suggestions, please discuss :)

Original: Large column  [WPF] Error: Parameter count mismatch ( using Dispatcher please note)


Guess you like

Origin www.cnblogs.com/petewell/p/11518155.html