PDA

View Full Version : TriggerCustomEvent


Ralph
03-30-2009, 12:51 PM
Hi,

for a program, implemented as indicator, I read data from a file during live session and store it in an internal data structure. This data structure is also accessed by the incoming tick data (OnBarUpdate). To avoid conflicts, I implemented NT's TriggerCustomEvent() to handle file reading. Works fine so far, but it has changed the error handling behaviour (try-catch). Therefore my question, how does TriggerCustomEvent() execute the code handed over to it?

a) Schedules the code execution and gives back program control immediately to the user code.
b) Schedules the code execution and block the user code until the code is executed.

I would suspect a), because that would explain the current error handling behaviour.

Regards
Ralph

NinjaTrader_Dierk
03-30-2009, 01:08 PM
No (b). The call blocks.

Ralph
03-30-2009, 01:59 PM
Ok.

- TriggerCustomEvent() schedules the user code.
- NT executes the user code eventually.
- User code throws an exception.
- The exception is caught by NT and reported to the control center's log tab and actually the catch-wrapper around TriggerCustomEvent() in the user code is never triggered.

Is that correct?

Regards
Ralph

NinjaTrader_Dierk
03-30-2009, 02:04 PM
Not sure I follow. If you try/catch your coding bugs then NT would never catch any exception.

I suggest starting with a simple as possible scenario to understand how the TriggerCustomEvent works.

Ralph
03-30-2009, 02:21 PM
Understand what you mean. Here is the correct explanation: The user code, we are talking about parses a text file. Syntax errors in the text file are "reported" by the user code by throwing an exception. But the exception is not caught by the code below, but is reported by NT in the log-tab.

Here is the related codeprivatevoid EventHandlerLoadMPs(Object sender, EventArgs eventArgs)
{
if (LoadConfig.ShowDialog() == DialogResult.OK)
{
try
{
using (StreamReader loadStream = new StreamReader (LoadConfig.OpenFile()))
{
profileInst.TriggerCustomEvent(LoadMPs, loadStream);
// Load(loadStream);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Configuration read error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}

NinjaTrader_Josh
03-30-2009, 02:31 PM
Ralph,

The error would have occurred somewhere in your custom event no? Could you not catch it in there?

Ralph
03-30-2009, 05:01 PM
Yes Josh, I think your proposal is a clean solution. I'll pull the try-catch and the using-section into my custom code. That way it is executed alltogether, whenever NT fires the scheduled user code.

Regards
Ralph