I start to get mad.. with delegates :-)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I have a client application which refer 2 asemblies A and B from different
name space:

1- Client application call a MethodA from AssemblyA
2- MethodA from assembly A call methodB from AssemblyB code
3- MethodeB from AssemblyB raise an event for any subscribers when code
inisde than method gets complete without error

How can I register to the event of MethodeB from an Assembly C ?

If I do AssemblyB myEvent +=new myEventHandler(myDelegateFunction)
then myDelagateFunction gets called only if f MethodeB is called from an
instance of AsemblyB but not throught the whole path AssemblyA ->Assembly B

Any ideas why ?

thnaks for help
serge


How can I
 
I was not able to reproduce your error.
My experiment was:

dll AssembylA : ref to AssemblyB
namespace AssemblyA
{
public class ClassA
{
public AssemblyB.ClassB objectB = new AssemblyB.ClassB();
public void methodA()
{
objectB.methodB();
}
}

dll AssemblyB : no refs
namespace AssemblyB
{
public class ClassB
{
public event EventHandler eventB;
public void methodB()
{
if (eventB != null)
eventB(this, EventArgs.Empty);
}
}
}

dll AssemblyC: ref to AssemblyB
namespace AssemblyC
{
public class ClassC
{
public ClassC(AssemblyB.ClassB objectB)
{
objectB.eventB += objectB_eventB;
}

protected void objectB_eventB(object sender, EventArgs e)
{
Console.WriteLine("objectB_eventB raised for for objectC");
}
}
}

exe Client: ref to AssemblyA, AssemblyB, AssemblyC
namespace deletaty
{
class Program
{
static void Main(string[] args)
{
AssemblyA.ClassA objA = new AssemblyA.ClassA();
AssemblyC.ClassC objC = new AssemblyC.ClassC(objA.objectB);
objA.methodA();
Console.ReadKey();
}
}
}

Result was as expected: "objectB_eventB raised for for objectC" has been
written in console window.

Best regards,
Jarosław Jaskułowski
Åódź, Polska
 
Thanks for our reply..

Assembly C as no reference to Assmbly B in my case otherwise I will have a
circular reference.

Chek the thread below this one for the way I have done it..May be you will
see a mistake !!
"Help on delegate strange behaviour"

My problem is when registering the events...It seem that it does not do it
from proper object ..

regards
serge
 
Back
Top