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.

1794 questions
7
votes
3 answers

A threading problem where mono hangs and MS.Net doesn't

I'm testing my app with mono in prevision of a Linux port, and I have a threading problem. I initially considered pasting 3000 code lines here, but finally I've devised a small minimal example ;) You have a form with a button (poetically named…
Clément
  • 12,299
  • 15
  • 75
  • 115
7
votes
2 answers

New form on a different thread

So I have a thread in my application, which purpose is to listen to messages from the server and act according to what it recieves. I ran into a problem when I wanted to fire off a message from the server, that when the client app recieves it, the…
Dan
  • 257
  • 1
  • 3
  • 11
7
votes
4 answers

How to invoke a Python method using its fully qualified name?

In Java I can invoke a class or method without importing it by referencing its fully qualified name: public class Example { void example() { //Use BigDecimal without importing it new java.math.BigDecimal(1); } } Similar…
noamt
  • 7,397
  • 2
  • 37
  • 59
7
votes
1 answer

List of delegates and invoking

I am creating a smaller RPG game in ASP.NET. In this game I have an items architecture, where each item has some methods. For instance, all items should share a method like "Drop", "Examine" and "Use". Some items will have to be extended with…
Lars Holdgaard
  • 9,496
  • 26
  • 102
  • 182
7
votes
4 answers

PHP5.3: "Call to undefined method" error when calling invoke from class variable

I have been doing some tests (to replace old code) with the __invoke magic method and I'm not sure this is a bug or not: Lets suppose we have a class: class Calc { function __invoke($a,$b){ return $a*$b; } } The following is…
lepe
  • 24,677
  • 9
  • 99
  • 108
7
votes
2 answers

Control.Invoke unwraps the outer exception and propagates the inner exception instead

The MessageBox.Show call below shows "Inner". Is this a bug? private void Throw() { Invoke(new Action(() => { throw new Exception("Outer", new Exception("Inner")); })); } private void button1_Click(object sender, EventArgs e) { …
Juan
  • 15,274
  • 23
  • 105
  • 187
7
votes
3 answers

Invoke() and BeginInvoke() behaving differently when executing an overridable method via a delegate

Can anyone tell me why this code behaves the way it does? See comments embedded in the code... Am I missing something really obvious here? using System; namespace ConsoleApplication3 { public class Program { static void Main(string[]…
7
votes
4 answers

Add a control on a form, from another Thread

I was trying to postpone adding controls to my main form, with a goal to speed up it's start time. Well I run in the following exception: Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was…
Gico
  • 1,276
  • 2
  • 15
  • 30
7
votes
7 answers

Cross-thread operation not valid in Windows Forms

Could anyone help me i have a problem I'm trying to get this code to work in the background via threadpool but i cannot seem to get it to work i keep getting this error: Cross-thread operation not valid: Control 'ListBox3' accessed from a thread…
Terrii
  • 385
  • 4
  • 8
  • 23
7
votes
1 answer

Dynamically calling a dll and method with arguments

Basically I'm trying to call a dll by name, instantiate an object, then call a method by name in that dll. I'm getting an "Exception has been thrown by the target of an invocation." during the Method.Invoke. I'm fairly sure my problem is with the…
crlanglois
  • 3,537
  • 2
  • 14
  • 18
7
votes
4 answers

Execute method on dynamic

I am sure this question has been answered somewhere but I'm having major problems finding the right combination of keywords to find it. I am curious to know if its possible to do something like this: dynamic someObj = new SomeObject(); var…
devshorts
  • 8,572
  • 4
  • 50
  • 73
6
votes
1 answer

Programmatically invoking validation on a TextBox

I'm writing unit tests to test whether data typed in the GUI is validated and recorded correctly. Currently I'm using code like this: using (MyControl target = new MyControl()) { PrivateObject accessor = new PrivateObject(target); TextBox…
Hand-E-Food
  • 12,368
  • 8
  • 45
  • 80
6
votes
2 answers

Should I use Invoke or SynchronizationContext to update form controls from another thread?

Trying to wrap my head around updating UI controls from other threads. Currently using BeginInvoke and honestly it's working fine but I keep hearing about how you can use SynchronizationContext as well to do the same thing. Which is preferred? Also,…
John Smith
  • 8,567
  • 13
  • 51
  • 74
6
votes
2 answers

alternative for using slow DynamicInvoke on muticast delegate

I have the following piece of code in a base-class: public static void InvokeExternal(Delegate d, object param, object sender) { if (d != null) { //Check each invocation target foreach (Delegate dDelgate in…
Emiswelt
  • 3,909
  • 1
  • 38
  • 56
6
votes
7 answers

how to pass variable argument to exe?

Okay, let's say that I have b.exe, which takes a string argument. I want to invoke b.exe within a.cpp, with system: string s1 = "hallo"; system("b.exe s1"); printf("s1 after invoke = %s",s1); and this is the code in b.cpp: int…
zia
  • 117
  • 3
  • 7