Invoke

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dani kotlar

    #1

    Invoke

    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?

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Invoke

    Dani,

    If you are calling Invoke on an implementation of ISynchronizeInv oke,
    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]
    - mvp@spam.guard. caspershouse.co m

    "dani kotlar" <dannykotlar@gm ail.comwrote in message
    news:1159991893 .188437.200000@ i3g2000cwc.goog legroups.com...
    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?
    >

    Comment

    • dani kotlar

      #3
      Re: Invoke

      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(s tring s);

      and an instance:

      private ChangeTextBox changeTextBox;

      which is instantiated in the constructor:

      changeTextBox = new ChangeTextBox(C hangeDisplayTex tBox);

      where ChangeDisplayTe xtBox is the method:

      public void ChangeDisplayTe xtBox(string s)
      {
      this.displayTex tBox.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

      Nicholas Paldino [.NET/C# MVP] wrote:
      Dani,
      >
      If you are calling Invoke on an implementation of ISynchronizeInv oke,
      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]
      - mvp@spam.guard. caspershouse.co m
      >
      "dani kotlar" <dannykotlar@gm ail.comwrote in message
      news:1159991893 .188437.200000@ i3g2000cwc.goog legroups.com...
      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?

      Comment

      Working...