G
Guest
Dear all,
I have a strange behaviour on the use of delagate. I will try to explain.
I have an assembly (Lets call it AssmDB) which contains database function
operation like Insert, Delete, Update... Wen one of this operation occurs, I
raise an event to any client subscribers.
Lets take as an example the Insert function as follow:
Step1:
====
AssmDB is inside namespace "Nomos.Plateform.DB"
// decalaration
public event DBEventHandler RaiseDBInsertEvent;
public Boolean Insert()
{
DBEventArgs m_dbArgs = new DBEventArgs(OccuredAt,DBAction.Insert);
try
{
... process insert operation here
//check if there is any subscriber to the event
// if no subscribers, no need to raise the events
if (DBInsert != null)
{
RaiseDBInsertEvent(OccuredAt,DBAction.Insert);
}
return true;
}
Then I compile this assembly to get it as AssmDb.dll
Step 2:
=====
Then I have a parent assembly (Lets call it AssmParent) which has reference
to the AssmDB.dll, and call the insert method as follow:
AssmParent is inside namespace "Client.DB"
using (Nomos.Plateform.DB action = new Nomos.Plateform.DB.Action())
{
return action.Insert();
}
Then I compile the assembly and get the AssmParent.dll
At this stage I have a AssmParent assembly which instantiate an Action
object from AssmDb.dll and call the insert method.
Then based on that the Insert method of assembly AssmDb.dll raide the event
DBInsert to any subscribers.
Step3:
=====
To test that I have created a client form application with reference with
both assenblies.
Then I create a button in which I create the registration to events that
might occurs during the Insert as describe above.
What I would like to get is that subscribers should answer to the DBInsert
event of AssmDB.
For that in my tets form I set the rgistration as follow
Nomos.Plateform.DB.Action action=new Nomos.Plateform.DB.Action() ;
action.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);
based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.
So far so good, and here is what happen.
As the event registration is done through an object belonging to the
Nomos.Plateform.DB namespace, event is not catch from the path:
AssmParent ->AssmDB.Insert
But only catch from the path AssmDB.Insert !!!
Any idea why it behaves like this ?
Is is due to different name space that I use for both class ?
Thnaks for your reply
serge
I have a strange behaviour on the use of delagate. I will try to explain.
I have an assembly (Lets call it AssmDB) which contains database function
operation like Insert, Delete, Update... Wen one of this operation occurs, I
raise an event to any client subscribers.
Lets take as an example the Insert function as follow:
Step1:
====
AssmDB is inside namespace "Nomos.Plateform.DB"
// decalaration
public event DBEventHandler RaiseDBInsertEvent;
public Boolean Insert()
{
DBEventArgs m_dbArgs = new DBEventArgs(OccuredAt,DBAction.Insert);
try
{
... process insert operation here
//check if there is any subscriber to the event
// if no subscribers, no need to raise the events
if (DBInsert != null)
{
RaiseDBInsertEvent(OccuredAt,DBAction.Insert);
}
return true;
}
Then I compile this assembly to get it as AssmDb.dll
Step 2:
=====
Then I have a parent assembly (Lets call it AssmParent) which has reference
to the AssmDB.dll, and call the insert method as follow:
AssmParent is inside namespace "Client.DB"
using (Nomos.Plateform.DB action = new Nomos.Plateform.DB.Action())
{
return action.Insert();
}
Then I compile the assembly and get the AssmParent.dll
At this stage I have a AssmParent assembly which instantiate an Action
object from AssmDb.dll and call the insert method.
Then based on that the Insert method of assembly AssmDb.dll raide the event
DBInsert to any subscribers.
Step3:
=====
To test that I have created a client form application with reference with
both assenblies.
Then I create a button in which I create the registration to events that
might occurs during the Insert as describe above.
What I would like to get is that subscribers should answer to the DBInsert
event of AssmDB.
For that in my tets form I set the rgistration as follow
Nomos.Plateform.DB.Action action=new Nomos.Plateform.DB.Action() ;
action.RaiseDBInsertEvent+= new InsertDelegate(InsertOccuredMethod);
based on the code above the registration is done by creating an instance of
the class which contains the event from AssmDb assembly.
So far so good, and here is what happen.
As the event registration is done through an object belonging to the
Nomos.Plateform.DB namespace, event is not catch from the path:
AssmParent ->AssmDB.Insert
But only catch from the path AssmDB.Insert !!!
Any idea why it behaves like this ?
Is is due to different name space that I use for both class ?
Thnaks for your reply
serge