B
bob
Hi,
maybe I am coding it wrong,
but declare an event in ClassA ( in dll) which I only want to
subscribe to in ClassB client Assy).
If I don't subscribe to it in ClassA then it fails with a null
exception when I try to raise it.
So I make a dummy routine that subscribes to it in ClassA and away we
go.
namespace myDllnamespace
{
public void delegate MySpecialEventhandler(object
sender,MySpecialEventArgs e);
public Interface MyInterface
{
event MySpecialEventhandler MyEvent;
void DoSomeStuff();
}
ClassA:MyInterface
{
public event MySpecialEventhandler MyEvent;
public ClassA()
{
MyEvent+=LocalSubscription;
}
public void DoSomeStuff()
{
LetsRaiseTheEvent();
}
private void LetsRaisetheEvent();
{
MySpecialEventArgs e = new MySpecialEventArgs {SpecialPayload =
something};
MyEvent(this,e); //***NULL EXCEPTION if local subscription is not
attended to.
}
private void LocalSubscription(object sender,MySpecialEventArgs e)
{
//Empty method but can't do with out it.
}
}
}
If my code is correct then there is a linkage between event raising
and event 'subscription'.
Haven't seen any mention of it in the documentation so I guess it is
just my methodology.
Is there a better way to do this? (Raise event in dll and consume in
client assy)
thanks
Bob
maybe I am coding it wrong,
but declare an event in ClassA ( in dll) which I only want to
subscribe to in ClassB client Assy).
If I don't subscribe to it in ClassA then it fails with a null
exception when I try to raise it.
So I make a dummy routine that subscribes to it in ClassA and away we
go.
namespace myDllnamespace
{
public void delegate MySpecialEventhandler(object
sender,MySpecialEventArgs e);
public Interface MyInterface
{
event MySpecialEventhandler MyEvent;
void DoSomeStuff();
}
ClassA:MyInterface
{
public event MySpecialEventhandler MyEvent;
public ClassA()
{
MyEvent+=LocalSubscription;
}
public void DoSomeStuff()
{
LetsRaiseTheEvent();
}
private void LetsRaisetheEvent();
{
MySpecialEventArgs e = new MySpecialEventArgs {SpecialPayload =
something};
MyEvent(this,e); //***NULL EXCEPTION if local subscription is not
attended to.
}
private void LocalSubscription(object sender,MySpecialEventArgs e)
{
//Empty method but can't do with out it.
}
}
}
If my code is correct then there is a linkage between event raising
and event 'subscription'.
Haven't seen any mention of it in the documentation so I guess it is
just my methodology.
Is there a better way to do this? (Raise event in dll and consume in
client assy)
thanks
Bob