Coffeehouse Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Exposing C# events using COM to JavaScript

Back to Forum: Coffeehouse
  • User profile image

    I want to create a C# dll which exposes events to JavaScript so I can send information back to the JavaScript when I want to. I want to create a C# dll which sends a string to a JavaScript code which listens to it every 3 seconds. So I've tried an MSDN article and wrote this:

    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Timers;
    using System.Runtime.InteropServices;
    namespace TimerNotifier
    public delegate void TimerEventHandler(string text);
    //Source interface for events to be exposed.
    //Add GuidAttribute to the source interface to supply an explicit System.Guid.
    //Add InterfaceTypeAttribute to indicate that interface is IDispatch interface.
    [GuidAttribute("93DA417C-878E-451E-8E77-270B306D128A") ]
    public interface TimerEvents
    //Add a DisIdAttribute to any members in the source
    //interface to specify the COM DispId.
    void TimerEvent(string text);
    //Add a ComSourceInterfaces attribute to the control to
    //identify the list of interfaces that are exposed as COM event sources.
    public class MyWindowControl
    //, ComInteropControlInterface
    event TimerNotifier.TimerEventHandler TimerEvent;
    public MyWindowControl() : base()
    Timer timer = new Timer();
    timer.Interval = 3000;
    timer.Elapsed += new ElapsedEventHandler(TimerHandler);
    private void TimerHandler(object sender, ElapsedEventArgs e)
    if (TimerEvent != null)


    However, when I try to raise the event by calling TimerEvent(DateTime.Now.ToString()); I get an error and the JS file never get to know about the event.

    Anyone knows how to raise events from a C# dll which will be handled by a JavaScript code?

    Oops - wrong forum. I thought I was posting in the Techoff forum.

  • User profile image

    I am trying to do the same thing and ran into the same problem.  If you have any additional information how to get this done I would love it.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.