1
我正在构建一个小型的ActiveX控件。我明白,ActiveX不能直接调用JavaScript函数,但需要通过事件工作。因此,我创建了一个事件,从codeproject的代码示例中复制而来。从activex调用javascript函数
这个事件似乎只适用于某些情况:当调用立即引发事件的javascript函数时,它会起作用。当我的javascript函数调用进行长时间的操作,只比引发该事件的ActiveX方法,这是行不通的,这里是我的意思的例子:
ActiveX事件:
[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
}
的调用示例的作品:
[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.
}
}
失败调用的一个例子:
[ComVisible(true)]
public void Open()
{
try
{
Start();
}
catch (Exception e)
{
throw e;
}
}
使用函数开始调用非常冗长的方法,每隔几分钟就会引发一次事件并将信息发送回javascript。
我似乎无法理解为什么它不起作用。少了什么东西?如果问题不清楚,我很抱歉,我得到的错误不清楚,所以只要问一问,我就会改进问题。