I'm creating an opc server using an .dll file.The write callback method & getting the following error at Application.Run():
A callback was made on a garbage collected delegate of type 'OPC_Library!OPC_Library.OPC_DLL+WriteNotificationDelegate::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive
by the managed application until it is guaranteed that they will never be called.
opcSrvr.cs
private static OPC_DLL.WriteNotificationDelegate writeCallBack;
public opcSrvr()
{
InitializeComponent();
writeCallBack = new OPC_DLL.WriteNotificationDelegate(myWriteCallBack);
}
public void myWriteCallBack(UInt32 hItem, ref Object Value, ref UInt32 ResultCode)
{
ResultCode = 0;
for (int i = 0; i < countTagHandle * 20; i++)
{
if (hItem == TagHandle[i])
{
tbSendText.Text = Convert.ToString(Value);
OPC_DLL.UpdateTag(TagHandle[i], tbSendText.Text, 192);
}
}
}
private void opcSrvr_Load(object sender, EventArgs e)
{
OPC_DLL.EnableWriteNotification(myWriteCallBack, true);
}