我一直在尝试向VBA客户端公开和触发事件。到目前为止,在VBA客户端,事件是公开的,我看到方法事件处理方法被添加到我的模块类中,但是VBA事件处理方法没有触发。由于某些原因,在调试时事件为null。使用synchronously修改我的代码也没有任何帮助。
根据记录,我已经检查了其他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();
}
这对所有赏金猎人来说是一场很好的演出,200个代表点
https://stackoverflow.com/questions/39511528
复制相似问题