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. C# - listen to add/remove function from event

C# - listen to add/remove function from event

Scheduled Pinned Locked Moved C#
questioncsharpcom
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

    how can i know when a function is been added/removed from my Event? I want to do some connection when a COM is add a function to my event.

    public delegate void DoItDelegate(int i);
    ....
    ....
    {
    DoItDelegate MyFunction;

    MyFunction += new DoItDelegate(DoItFunction);

    }

    public void DoItFunction(int i)
    {
    //Do Domthing
    }

    When the command : "MyFunction += new DoItDelegate(DoItFunction); " is been execute i want to do something in another function. What can i do if i want to know when this "MyFunction += new DoItDelegate(DoItFunction);" is execute and register it to Datatable? (The command "MyFunction += new DoItDelegate(DoItFunction);" is in the COM code and not in my code so i can't control it.)

    D A 2 Replies Last reply
    0
    • B bonzaiholding

      how can i know when a function is been added/removed from my Event? I want to do some connection when a COM is add a function to my event.

      public delegate void DoItDelegate(int i);
      ....
      ....
      {
      DoItDelegate MyFunction;

      MyFunction += new DoItDelegate(DoItFunction);

      }

      public void DoItFunction(int i)
      {
      //Do Domthing
      }

      When the command : "MyFunction += new DoItDelegate(DoItFunction); " is been execute i want to do something in another function. What can i do if i want to know when this "MyFunction += new DoItDelegate(DoItFunction);" is execute and register it to Datatable? (The command "MyFunction += new DoItDelegate(DoItFunction);" is in the COM code and not in my code so i can't control it.)

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      You mention 'my event' but I don't see any events in your code, only a delegate. If you are using events then you can use the add and remove methods and call your other function there.

      public class DoItUser
      {
      public DoItUser()
      {
      MyClass myClass = new MyClass();
      myClass.MyEvent += new DoItDelegate(DoItFunction);
      }

      private void DoItFunction(int i)
      {
          // ...
      }
      

      }

      public delegate void DoItDelegate(int i);

      public class MyClass
      {
      private DoItDelegate myEvent;

      public event DoItDelegate MyEvent
      {
          add
          {
              myEvent += value;
              DoSomethingElse();
          }
          remove { myEvent -= value; }
      }
      
      private void DoSomethingElse()
      {
          // ...
      }
      

      }

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Why are you using VB6? Do you hate yourself? (Christian Graus)

      1 Reply Last reply
      0
      • B bonzaiholding

        how can i know when a function is been added/removed from my Event? I want to do some connection when a COM is add a function to my event.

        public delegate void DoItDelegate(int i);
        ....
        ....
        {
        DoItDelegate MyFunction;

        MyFunction += new DoItDelegate(DoItFunction);

        }

        public void DoItFunction(int i)
        {
        //Do Domthing
        }

        When the command : "MyFunction += new DoItDelegate(DoItFunction); " is been execute i want to do something in another function. What can i do if i want to know when this "MyFunction += new DoItDelegate(DoItFunction);" is execute and register it to Datatable? (The command "MyFunction += new DoItDelegate(DoItFunction);" is in the COM code and not in my code so i can't control it.)

        A Offline
        A Offline
        Afjal khan
        wrote on last edited by
        #3

        public delegate void DoItDelegate(int i);........{DoItDelegate MyFunction;MyFunction += new DoItDelegate(DoItFunction); }public void DoItFunction(int i){ //Do Domthing}

        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