Creating an automation with event(s)

frankmortensenfrankmortensen Member Posts: 42
Hi

I am trying to create an automation (class library) in C#.
The automation has one event.
Can someone please tell me how an automation needs to look like in order for Navision to be able to see the event and automatically generate the trigger for the event that my automation provides (MyAutomation::MyEvent...).

Here's what I have so far:

using System;
using System.Runtime.InteropServices;
public delegate void MyDelegate();
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IMyClass
{
event MyDelegate MyEvent;
}
[ClassInterface(ClassInterfaceType.None)]
public class MyClass : IMyClass
{
public event MyDelegate MyEvent;
public void TriggerTheEvent()
{
if (MyEvent != null)
MyEvent();
}
}

/Frank Mortensen

Comments

  • ta5ta5 Member Posts: 1,164
    I think RaiseEvent is the command you need.

    Try this
    http://www.mibuso.com/forum/viewtopic.php?t=8159
  • frankmortensenfrankmortensen Member Posts: 42
    Thanks for the quick reply. The 3rd line from the bottom is the line that raises the event (in C#). But I haven't even come as far as trying to raise any events as Navision doesn't recognise my event and therefor doesn't create the event trigger inside Navision. (Single instance and with events are set to yes).

    /Frank
  • DenSterDenSter Member Posts: 8,307
    Setting the WithEvents property to yes should do the trick automatically, and the event trigger should automatically appear when you close the variables window.

    What I did see a few times is when I forgot to set the property, saved the codeunit and discovered that it wasn't there. When I then set the property, it did not appear. I then had to remove the variable, save and close the codeunit, re-open it and create the variable with events. It's a pain in the neck sometimes, but those are things you should try before questioning your C# code.
  • kinekine Member Posts: 12,562
    You need to make the event public in the interface...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • frankmortensenfrankmortensen Member Posts: 42
    I am pretty sure that the Navision side is working.
    I am unsure about the C# code though.

    How can I set can I set an event public (or private) inside an interface?

    /Frank
  • frankmortensenfrankmortensen Member Posts: 42
    Do any of you guys have a the source code for c-sharp project that I might have a look at?

    /Frank
Sign In or Register to comment.