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
29
votes
14 answers

Avoid calling Invoke when the control is disposed

I have the following code in my worker thread (ImageListView below is derived from Control): if (mImageListView != null && mImageListView.IsHandleCreated && !mImageListView.IsDisposed) { if (mImageListView.InvokeRequired) …
Ozgur Ozcitak
  • 10,409
  • 8
  • 46
  • 56
28
votes
3 answers

Using the C# Dispatcher in WPF Applications

I'm building a chat client and am not 100% sure on how to use the dispatcher. So the question is I have a method as such: public void LostConnection() { myGUI.chatBox.AppendText("Lost connection to room: "+ myGUI.UsernameText.ToString() +…
Tombo890
  • 371
  • 1
  • 3
  • 11
28
votes
5 answers

Using C# MethodInvoker.Invoke() for a GUI app... is this good?

Using C# 2.0 and the MethodInvoker delegate, I have a GUI application receiving some event from either the GUI thread or from a worker thread. I use the following pattern for handling the event in the form: private void SomeEventHandler(object…
Stécy
  • 11,951
  • 16
  • 64
  • 89
26
votes
1 answer

Getting a return value from a methodInfo.invoke

How do I get a return value (int) from a methodInfo.invoke? What makes it difficult for me is the fact that I use a string variable to call the method. Check the example below: if (Convert.ToBoolean(getParameterFromXML("issue", k, 1)) == true) { …
user1688175
25
votes
3 answers

Dynamically invoke properties by string name using VB.NET

I'm currently working on a project where a section of the code looks like this: Select Case oReader.Name Case "NameExample1" Me.Elements.NameExample1.Value = oReader.ReadString ' ... Case "NameExampleN" …
Tom
  • 15,527
  • 5
  • 48
  • 62
24
votes
2 answers

How catch return value in a Powershell script

I have a powershell script (.ps1) that execute other Powershell script that has a return value. I invoke to the script with this command: $result = Invoke-Expression -Command ".\check.ps1 $fileCommon" Write-Output $result The output is only the…
gtx911
  • 1,189
  • 4
  • 25
  • 46
23
votes
3 answers

How to invoke a method which throws an Exception using Java Reflection?

I would like to invoke a method, using Java Reflection. The problem is that this method (which I wrote) throws an Exception (I created a myCustomException). When I add a try/catch clause, I can't run my project, because Eclipse says "the catch…
cleroo
  • 1,145
  • 2
  • 11
  • 17
22
votes
2 answers

The uncatchable exception, pt 2

Update: I've filed a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/568271/debugger-halting-on-exception-thrown-inside-methodinfo-invoke#details If you can reproduce this problem on your machine, please…
devios1
  • 36,899
  • 45
  • 162
  • 260
22
votes
7 answers

WPF Dispatcher.Invoke 'hanging'

I have a somewhat complex WPF application which seems to be 'hanging' or getting stuck in a Wait call when trying to use the dispatcher to invoke a call on the UI thread. The general process is: Handle the click event on a button Create a new…
Matthew Savage
  • 3,794
  • 10
  • 43
  • 53
22
votes
3 answers

PowerShell Invoke-Sqlcmd switches into sqlps session

I am writing a script in PowerShell ISE and I am using Invoke-Sqlcmd. After the command is executed the Powershell session switches into sqlps session (PS SQLSERVER:>) and I can't execute script for the second time. I have to quit PowerShell ISE and…
scar80
  • 1,642
  • 2
  • 18
  • 36
22
votes
3 answers

How to call the __invoke method of a member variable inside a class

PHP 5.4.5, here. I'm trying to invoke an object which is stored as a member of some other object. Like this (very roughly) class A { function __invoke () { ... } } class B { private a = new A(); ... $this->a(); <-- runtime error…
Jules May
  • 753
  • 2
  • 10
  • 18
21
votes
4 answers

How to get PowerShell to wait for Invoke-Item completion?

How do I get PowerShell to wait until the Invoke-Item call has finished? I'm invoking a non-executable item, so I need to use Invoke-Item to open it.
arathorn
  • 2,098
  • 3
  • 20
  • 29
21
votes
2 answers

Isn't blindly using InvokeRequired just bad practice?

I am a novice programmer so I could be completely mistaken here, but this issue bugs me more then it should. This is actually a follow-up from this question. The accepted answer was, that you have to call InvokeRequired in order to avoid some…
Jordy
  • 1,816
  • 16
  • 29
21
votes
3 answers

MethodInfo.Invoke performance issue

I am reading and writing data to and from a file. The data in the file can be floats, doubles, ints etc. The type is not known until runtime. I will refer to data type stored in the file as Tin. Data is read into or written from arrays of type Tout.…
Basil Furdas
  • 211
  • 1
  • 2
  • 3
19
votes
5 answers

Invoke and BeginInvoke

Greetings, I am developing some application in C#. At the moment I'm dealing with threading and I have a question that I have in my mind. What is the difference between Invoke and BeginInvoke? I read some thread and I found some useful information…
niao
  • 4,972
  • 19
  • 66
  • 114