KMC
KMC

Reputation: 20046

Cannot pass arguments in dispatcher.invoke

I will need to convert the following VB Form code to WPF C#:

// VB
Me.Invoke(New FooDelegate(AddressOf Foo), New Object() {cmd})

Where Foo is just a method taking a string argument cmd.

I tried all the following in WPF C#, but all giving me exception:

//C#
dispatcher.Invoke(new FooDelegate(Foo()), cmd);
dispatcher.Invoke(new FooDelegate(Foo(cmd)), cmd); 
dispatcher.Invoke(new FooDelegate(Foo()), new object() {cmd});

What is the correct formatting?

Upvotes: 0

Views: 2393

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100537

You are calling function with () instead of geting its address. Unless ProcessCommandCT returns function it should be something like:

dispatcher.Invoke(new ProcessCommandDelegate(ProcessCommandCT), cmd); 

Upvotes: 4

Related Questions