Invoke

  • Thread starter Thread starter dani kotlar
  • Start date Start date
D

dani kotlar

Is it possible to pass the Invoke or BeginInvoke functions as a
parameter a delegate encapsulating a function with a non empty set of
parameters? How is it done?
 
Dani,

If you are calling Invoke on an implementation of ISynchronizeInvoke,
then there is an array as the second parameter that takes the parameters you
are going to pass to the delegate.

If you are calling Invoke on a delegate, then the parameter list is the
same as the signature of the delegate and you can pass what you want.

Hope this helps.
 
Nicholas,
I am not sure how to do it. Here is the situation: I have a textBox
named displayTextBox in a form, that was created in one thread. Another
thread tries to change it's text, but it can't, thanks to the changes
in .NET 2.0, since this is a cross-thread operation. So I added a
delegate to the form:

public delegate void ChangeTextBox(string s);

and an instance:

private ChangeTextBox changeTextBox;

which is instantiated in the constructor:

changeTextBox = new ChangeTextBox(ChangeDisplayTextBox);

where ChangeDisplayTextBox is the method:

public void ChangeDisplayTextBox(string s)
{
this.displayTextBox.Text = s;
}

of the form class.

I wrote a named method instead of using an anonymous method, since this
operation of changing the text in the text box happens often.

Now, how do I actually Invoke the delegate changeTextBox?

Dani
Dani,

If you are calling Invoke on an implementation of ISynchronizeInvoke,
then there is an array as the second parameter that takes the parameters you
are going to pass to the delegate.

If you are calling Invoke on a delegate, then the parameter list is the
same as the signature of the delegate and you can pass what you want.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

dani kotlar said:
Is it possible to pass the Invoke or BeginInvoke functions as a
parameter a delegate encapsulating a function with a non empty set of
parameters? How is it done?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top