Hi all,
I am building a small activex control. I understood that activex cannot call a javascript funtion directly, but needs to work through events. Therefore I've created an event, copied from a code sample from codeproject.
The event seems to work only on certain circumstances: It works when a call is made to a javascript function which immediately raises the event. It does not work when my javascript function calls an activex method that performs long operation and only than raise the event, here is an example of what I mean:
Activex event:
[Guid("68BD4E0D-D7BC-4cf6-BEB7-CAB950161E79")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ControlEvents
{
//Add a DispIdAttribute to any members in the source interface to specify the COM DispId.
[DispId(0x60020001)]
void OnClose(string redirectUrl); //This method will be visible from JS
}
Example of the call that works:
[ComVisible(true)]
public void Close()
{
if (OnClose != null)
{
OnClose("my test"); //Calling event that will be catched in JS
}
else
{
MessageBox.Show("No Event Attached"); //If no events are attached send message.
}
}
An example of the call that fails:
[ComVisible(true)]
public void Open()
{
try
{
Start();
}
catch (Exception e)
{
throw e;
}
}
With the function Start calling a very lengthy method that in turn raises events once every few minutes and send information back to javascript.
I can't seem to understand why it won't work. What's missing? I am sorry if the question is not clear, the error I am getting is not clear either so just ask and I'd refine the question.