Managing subscription events
The signature of the methods to which event handler delegates point takes the form:
void <method name> ( object sender, <object derived from EventArgs> args )
The first argument is a reference to the request object. As it is passed as a System.Object
, you must cast it to the appropriate type of the request object before using it. The following example shows how to cast the request sender as an InstrumentLookup object:
public void doInstrumentLookup()
{
InstrumentLookup m_req = new InstrumentLookup(
tt_net_sdk.Dispatcher.Current,
MarketId.CME, ProductType.Future, "CL", "CL Dec19");
m_req.OnData += new EventHandler(m_req_OnData);
m_req.GetAsync();
}
void m_req_OnData(object sender, InstrumentLookupEventArgs e)
{
InstrumentLookup m_req = (InstrumentLookup)sender;
/* code omitted */
}