I'm trying receive notification in Windows Service, but the event doesn't fire. I read some posts in forum, i set Synchronize property to false, but the notification doesn't work.
My code:
protected override void OnStart(string[] args)
{
adsclient.Synchronize = false;
ReceiveNotifications();
}
private void ReceiveNotifications()
{
//create subscription
adsclient.Connect("192.168.118.133.1.1", 801);
adsclient.AdsNotificationEx += Client_AdsNotification;
WriteLog("Status Servidor: " + adsclient.IsConnected.ToString());
int notificationHandle = 0;
try
{
notificationHandle = adsclient.AddDeviceNotificationEx(".StatusDisjuntor", AdsTransMode.OnChange, 500, 0, null, typeof(bool));
WriteLog(notificationHandle.ToString());
}
finally
{
adsclient.DeleteDeviceNotification(notificationHandle);
adsclient.AdsNotificationEx -= Client_AdsNotification;
}
}
private void Client_AdsNotification(object sender, AdsNotificationExEventArgs e)
{
bool status = (bool)e.Value;
WriteLog("Mudança de status do disjuntor: " + status.ToString());
}
What i'm doing wrong? Any ideas?
Thanks a lot!