Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Interesting problem.</p> <p><code>WithEvents</code> property on automation creates the handler and attaches it to <code>Elapsed</code> delegate, so this one is not <code>NULL</code> - hence no exception</p> <p>However, when <code>WithEvents</code> is <code>No</code>, and <code>Timer.Start()</code> is invoked, as you rightly say no exception bubbles up, even though (in theory) <code>Elapsed</code> delegate is null.</p> <p>The simple explanation to this would be, that NAV attaches empty delegate regardless of <code>WithEvents</code> property. To support that, if you put code in <code>Timer::Elapsed()</code> trigger, then take off <code>WithEvents</code>, and bring it back - the code will still be there (i.e. trigger still exists in unchanged form), which makes me lean towards conclusion that it exists always (i.e. empty delegate).</p> <p>But of course it's NAV so it couldn't be that simple.</p> <p>I created a test codeunit from above MSDN example, but made a small change to the automation:</p> <pre><code>/// &lt;summary&gt; /// Whenever the internal timer elapses, an event must be fired /// &lt;/summary&gt; private void mTimer_Elapsed(object sender, ElapsedEventArgs e) { OnElapsed(EventArgs.Empty); throw null; } </code></pre> <p>This, in theory, should throw <code>NULL</code> whenever <code>mTimer_Elapsed</code> is invoked - nothing however bubbles up in NAV. I went a bit further and changed this:</p> <pre><code>///&lt;summary&gt; /// Invoke the Changed event; called whenever the internal timer elapses /// &lt;/summary&gt; protected virtual void OnElapsed(EventArgs e) { throw new InvalidCastException("test"); //Elapsed(); } </code></pre> <p>Again, nothing happens in NAV.</p> <p>Note, that both changes behave as expected if the <code>COM Timer</code> is consumed from within .NET project. This makes me think, that NAV Interop must be capturing exceptions from the automation and handle them internally.</p> <p>I would however pop that question in <a href="http://mibuso.com/" rel="nofollow">Mibuso</a> - someone there will probably know better.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload