Reputation: 131
Can someone explain what is wrong with this code? This event will not fire when I make a call to mco.
private ModiconComunications.ModiconComObject withEventsField_mco = new ModiconComunications.ModiconComObject();
private ModiconComunications.ModiconComObject mco
{
get { return withEventsField_mco; }
set
{
if (withEventsField_mco != null)
{
withEventsField_mco.GetDataReturn -= mco_GetDataReturn;
}
withEventsField_mco = value;
if (withEventsField_mco != null)
{
withEventsField_mco.GetDataReturn += mco_GetDataReturn;
}
}
}
When I call the below line, it should fire off the event mco_GetDataReturn, however, it does not. What have I done incorrectly?
mco.GetData(ModiconComunications.ModiconComObject.GetDataType.READ_MODICON_HREGS, 11421, 9, 0);
Upvotes: 0
Views: 115
Reputation: 2786
A little more code would be helpfull.
You init withEventsField_mco with a new object. However since you don't use the setter on the mco property no events get wired.
try this to test this reasonig:
McocontainingObject.mco = new ModiconComunications.ModiconComObject();
mco.GetData(ModiconComunications.ModiconComObject.GetDataType.READ_MODICON_HREGS, 11421, 9, 0);
or in your constructor
class McoContainer{
private ModiconComunications.ModiconComObject withEventsField_mco;
public McoContainer(){
this.mco = new ModiconComunications.ModiconComObject();
}
public ModiconComunications.ModiconComObject mco{
get{...}
set{...}
}
}
Upvotes: 1
Reputation: 45135
Well, you initial withEventsField_mco, the one that is created by this line:
private ModiconComunications.ModiconComObject withEventsField_mco = new ModiconComunications.ModiconComObject();
Doesn't get it's event handlers hooked up. Unless you are doing that in the constructor.
Upvotes: 3