有一个事件处理方法定义如下:
public delegate void DIOPCGroupEvent_AsyncReadCompleteEventHandler([In] int TransactionID, [In] int NumItems, [In][MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)] ref Array ClientHandles, [In][MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array ItemValues, [In][MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)] ref Array Qualities, [In][MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_DATE)] ref Array TimeStamps, [In][MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)] ref Array Errors);
正常的订阅处理:
group.AsyncReadComplete += new DIOPCGroupEvent_AsyncReadCompleteEventHandler(Event_AsyncReadComplete);
private void Event_AsyncReadComplete(int TransactionID, int NumItems, ref Array ClientHandles,ref Array ItemValues, ref Array Qualities, ref Array TimeStamps, ref Array Errors)
{
_logger.LogInformation("异步读取响应事件:raansactionId:{},结果个数:{},结果值:{}", TransactionID,ItemValues.Length,ItemValues);
for (int i = 1; i <= NumItems; i++)
{
object resVal = ItemValues.GetValue(i);
object resQualitie = Qualities.GetValue(i);
object resTime = TimeStamps.GetValue(i);
object resError = Errors.GetValue(i);
_logger.LogInformation("响应时间:{},返回值:{},数据质量:{},响应异常:{}", resTime, resVal, resQualitie, resError);
}
}
目前我的需求是需要在处理事件的时候需要多填一个参数,如string name之类的该如何做呢?
楼主不了解c#,只是目前有一个需求需要调用dll,故采用c#来写。好在c#和java还是比较像的,之前只在c语言中文网看了两个小时教程,就上手实现功能了,一般语法没问题,但是稍微高级一点的语法感觉就不知道该怎么弄了,求教
写一个有所有参数的类:
改委托定义:
更改事件处理器的签名:
那用的第三方的话: