Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Invoke a function every time that a function is been added to my event

Invoke a function every time that a function is been added to my event

Scheduled Pinned Locked Moved C#
questioncomtutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bonzaiholding
    wrote on last edited by
    #1

    I want to call to a function every time that a function is add to my Event. How can i do it? Example for this kind of code:

    public delegate void DoItDelegate(int i);
    public partial class Form1 : Form
    {
    public DoItDelegate MyFunction;
    public int Count=0;
    public Form1()
    {
    InitializeComponent();
    //EveryTime that a function been added to this delegate (MyFunction)
    //I want that the counter will be reset to 0 (Counter=0)
    //The client can add a function to MyFunction throw DLL COM and not just in my code.
    //How can i control it and every time reset to Counter to zero?
    RegisterTheNewMethod();
    MyFunction += new DoItDelegate(DoItFunction);
    MyFunction.Invoke(32);
    }

        public void DoItFunction(int i)
        {
            Count++;
            int j = i;
            //Do Domthing
        }
        //I want to call this function every time that a new Function is added to the Event "MyFunction"
        public void RegisterTheNewMethod()
        {
            Count = 0;
            //Do other things as well
        }
    }
    

    Every time that this kind of command (MyFunction += new DoItDelegate(DoItFunction);)is been called and the function is been added to the Event MyFunction i want to invoke some function (In this example RegisterTheNewMethod()). How can i do it?

    OriginalGriffO P 2 Replies Last reply
    0
    • B bonzaiholding

      I want to call to a function every time that a function is add to my Event. How can i do it? Example for this kind of code:

      public delegate void DoItDelegate(int i);
      public partial class Form1 : Form
      {
      public DoItDelegate MyFunction;
      public int Count=0;
      public Form1()
      {
      InitializeComponent();
      //EveryTime that a function been added to this delegate (MyFunction)
      //I want that the counter will be reset to 0 (Counter=0)
      //The client can add a function to MyFunction throw DLL COM and not just in my code.
      //How can i control it and every time reset to Counter to zero?
      RegisterTheNewMethod();
      MyFunction += new DoItDelegate(DoItFunction);
      MyFunction.Invoke(32);
      }

          public void DoItFunction(int i)
          {
              Count++;
              int j = i;
              //Do Domthing
          }
          //I want to call this function every time that a new Function is added to the Event "MyFunction"
          public void RegisterTheNewMethod()
          {
              Count = 0;
              //Do other things as well
          }
      }
      

      Every time that this kind of command (MyFunction += new DoItDelegate(DoItFunction);)is been called and the function is been added to the Event MyFunction i want to invoke some function (In this example RegisterTheNewMethod()). How can i do it?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Did you not read the answers to your earlier post? So why post the same again?

      All those who believe in psycho kinesis, raise my hand.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • B bonzaiholding

        I want to call to a function every time that a function is add to my Event. How can i do it? Example for this kind of code:

        public delegate void DoItDelegate(int i);
        public partial class Form1 : Form
        {
        public DoItDelegate MyFunction;
        public int Count=0;
        public Form1()
        {
        InitializeComponent();
        //EveryTime that a function been added to this delegate (MyFunction)
        //I want that the counter will be reset to 0 (Counter=0)
        //The client can add a function to MyFunction throw DLL COM and not just in my code.
        //How can i control it and every time reset to Counter to zero?
        RegisterTheNewMethod();
        MyFunction += new DoItDelegate(DoItFunction);
        MyFunction.Invoke(32);
        }

            public void DoItFunction(int i)
            {
                Count++;
                int j = i;
                //Do Domthing
            }
            //I want to call this function every time that a new Function is added to the Event "MyFunction"
            public void RegisterTheNewMethod()
            {
                Count = 0;
                //Do other things as well
            }
        }
        

        Every time that this kind of command (MyFunction += new DoItDelegate(DoItFunction);)is been called and the function is been added to the Event MyFunction i want to invoke some function (In this example RegisterTheNewMethod()). How can i do it?

        P Offline
        P Offline
        petercrab
        wrote on last edited by
        #3

        hi, I am not sure how to call method every time you add to a delegate. Why don't you call the method after the delegate is added . e.g MyFunction += new DoItDelegate(DoItFunction); RegisterTheNewMethod();

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups