Questions tagged [invoke]

Executes the specified delegate on the thread that owns the control's underlying window handle.

The Invoke method searches up the control's parent chain until it finds a control or form that has a window handle if the current control's underlying window handle does not exist yet. If no appropriate handle can be found, the Invoke method will throw an exception.

1692 questions
714
votes
22 answers

How do I invoke a Java method when given the method name as a string?

If I have two variables: Object obj; String methodName = "getName"; Without knowing the class of obj, how can I call the method identified by methodName on it? The method being called has no parameters, and a String return value. It's a getter for…
brasskazoo
  • 68,343
  • 22
  • 59
  • 74
617
votes
22 answers

Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on

I have a scenario. (Windows Forms, C#, .NET) There is a main form which hosts some user control. The user control does some heavy data operation, such that if I directly call the UserControl_Load method the UI become nonresponsive for the duration…
Prerak K
  • 10,150
  • 7
  • 26
  • 36
415
votes
6 answers

What's the difference between Invoke() and BeginInvoke()

Just wondering what the difference between BeginInvoke() and Invoke() are? Mainly what each one would be used for. EDIT: What is the difference between creating a threading object and calling invoke on that and just calling BeginInvoke() on a…
Nathan W
  • 50,657
  • 24
  • 92
  • 142
331
votes
13 answers

What could cause java.lang.reflect.InvocationTargetException?

Well, I've tried to understand and read what could cause it but I just can't get it: I have this somewhere in my code: try{ .. m.invoke(testObject); .. } catch(AssertionError e){ ... } catch(Exception e){ .. } Thing is that, when it tries…
user550413
  • 4,183
  • 4
  • 22
  • 26
210
votes
10 answers

Reflection: How to Invoke Method with parameters

I am trying to invoke a method via reflection with parameters and I get: object does not match target type If I invoke a method without parameters, it works fine. Based on the following code if I call the method Test("TestNoParameters"), it works…
Ioannis
  • 2,655
  • 4
  • 22
  • 19
198
votes
6 answers

Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on

I want to send temperature value from a microcontroller using UART to C# interface and Display temperature on Label.Content. Here is my microcontroller code: while(1) { key_scan(); // get value of temp if (Usart_Data_Ready()) { …
Fatima Zohra
  • 2,629
  • 2
  • 15
  • 16
139
votes
1 answer

Difference Between Invoke and DynamicInvoke

What is the difference between Invoke and DynamicInvoke in delegates? Please give me some code example which explain difference between that two methods.
testCoder
  • 6,587
  • 13
  • 49
  • 72
103
votes
5 answers

Javascript dynamically invoke object method from string

Can I dynamically call an object method having the method name as a string? I would imagine it like this: var FooClass = function() { this.smile = function() {}; } var method = "smile"; var foo = new FooClass(); // I want to run smile on the…
Mikulas Dite
  • 7,202
  • 9
  • 52
  • 94
96
votes
9 answers

Invoke(Delegate)

Can anybody please explain this statement written on this link Invoke(Delegate): Executes the specified delegate on the thread that owns the control's underlying window handle. Can anybody explain what this means (especially the bold one) I am not…
user1903439
  • 1,791
  • 5
  • 17
  • 28
90
votes
2 answers

Func() vs Func.Invoke()

I'm curious about the differences between calling a Func directly vs. using Invoke() on it. Is there a difference? Is the first syntactical sugar and calls Invoke() underneath anyway? public T DoWork(Func method) { return…
tris
  • 1,460
  • 2
  • 16
  • 28
76
votes
3 answers

How to use Reflection to Invoke an Overloaded Method in .NET

Is there a way to Invoke an overloaded method using reflection in .NET (2.0). I have an application that dynamically instantiates classes that have been derived from a common base class. For compatibility purposes, this base class contains 2…
Wes P
  • 9,102
  • 14
  • 39
  • 48
70
votes
8 answers

How to execute a method passed as parameter to function

I want to write my own function in JavaScript which takes a callback method as a parameter and executes it after the completion, I don't know how to invoke a method in my method which is passed as an argument. Like Reflection. example code function…
Muhammad Ummar
  • 3,426
  • 4
  • 36
  • 68
64
votes
5 answers

How do I invoke a private static method using reflection (Java)?

I would like to invoke a private static method. I have its name. I've heard it can be done using Java reflection mechanism. How can I do it? EDIT: One problem I encountered when trying to invoke the method is how to specify the type of its argument.…
snakile
  • 47,358
  • 57
  • 160
  • 231
63
votes
3 answers

How to call a method stored in a HashMap? (Java)

I have a list of commands (i, h, t, etc) that the user will be entering on a command line/terminal Java program. I would like to store a hash of command/method pairs: 'h', showHelp() 't', teleport() So that I can have code something like: HashMap…
cwhiii
  • 1,316
  • 2
  • 12
  • 15
61
votes
7 answers

MethodInvoker vs Action for Control.BeginInvoke

Which is more correct and why? Control.BeginInvoke(new Action(DoSomething), null); private void DoSomething() { MessageBox.Show("What a great post"); } or Control.BeginInvoke((MethodInvoker) delegate { MessageBox.Show("What a great…
Mike_G
  • 14,627
  • 11
  • 63
  • 93
1
2 3
99 100