C# - listen to add/remove function from event
-
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.)
-
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.)
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) -
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.)
public delegate void DoItDelegate(int i);........{DoItDelegate MyFunction;MyFunction += new DoItDelegate(DoItFunction); }public void DoItFunction(int i){ //Do Domthing}