我一直在尝试向VBA客户端公开和触发一个事件。到目前为止,在VBA客户端方面,事件已经被公开,并且我看到了事件处理方法添加到我的模块类中,但是VBA事件处理方法没有触发。出于某种原因,在调试时事件为空。修改我的代码并同步执行也没有帮助。
值得一提的是,我已经查看了其他SO问题,但它们没有帮助。
非常感谢任何好的答案。
值得一提的是,我已经查看了其他SO问题,但它们没有帮助。
非常感谢任何好的答案。
[ComVisible(true)]
[Guid("56C41646-10CB-4188-979D-23F70E0FFDF5")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IWebEvents))]
[ProgId("MyAssembly.MyClass")]
public class MyClass : ServicedComponent, IMyClass
{
public string _address { get; private set; }
public string _filename { get; private set; }
[DispId(4)]
public void DownloadFileAsync(string address, string filename)
{
_address = address;
_filename = filename;
System.Net.WebClient wc = new System.Net.WebClient();
Task.Factory.StartNew(() => wc.DownloadFile(_address, _filename))
.ContinueWith((t) =>
{
if (null != this.OnDownloadCompleted)
OnDownloadCompleted();
});
}
public event OnDownloadCompletedEventHandler OnDownloadCompleted;
}
[ComVisible(false)]
public delegate void OnDownloadCompletedEventHandler();
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IWebEvents
{
[DispId(1)]
void OnDownloadCompleted();
}