c#调用回调问题
// delegatepublic void RefListCallBack(uint dwCallbackData, uint dwAddr, uint dwVarID, int nData)
{
Console.WriteLine("Id=" + dwVarID.ToString() + " Data=" + nData.ToString());
// dwCallbackData ... will be 2345 (user specified)
// dwAddr ........... lasalid of changed server
// dwVarID .......... will be 88 or 99 (user specified)
// nData ............ changed value (datasize <= 32bit) or crc32 of changed data (datasize > 32bit)
//... // user has to act on changed value
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Lasal32.CB_RLADD_FUNCTYPE methptr = new Lasal32.CB_RLADD_FUNCTYPE(RefListCallBack);
// GC.KeepAlive(methptr);
this.iRlb = Lasal32.LslRefreshListCreateExt("TCP:10.10.150.37;ApplID=10", 0, 0, 0, null, methptr, 2345, 10000);
if (this.iRlb != 0)
{
if (Lasal32.LslRefreshListGetVarInfo(this.iRlb, "Obj_Csharptest1.ListServer", ref this.var1) == true)
Lasal32.LslRefreshListAdd(this.iRlb, ref this.var1, 88, 100, Lasal32.CpReflist.RF_DYNAMIC); // add entry to refreshlist
if (Lasal32.LslRefreshListGetVarInfo(this.iRlb, "Obj_Csharptest1.Position", ref this.var2) == true)
Lasal32.LslRefreshListAdd(this.iRlb, ref this.var2, 99, 100, Lasal32.CpReflist.RF_DYNAMIC); // add entry to refreshlist
// ... add some more if you want
Lasal32.LslRefreshListStart(this.iRlb, Lasal32.CpReflist.RF_DYNAMIC); // start refreshlist
// ... watch outputwindow
}
}
老师们,请问下 我如何读取RefListCallBack里面的数据呢,每次会弹出“对“OnlineSigmatek!OnlineSigmatek.Lasal32+CB_RLADD_FUNCTYPE::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。”