0

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!

  • Maybe you can first try the [example from InfoSys](https://infosys.beckhoff.com/content/1033/tc3_ads.net/9407534859.html?id=1030953525419128638). If that works, you can use that as a base. If it doesn´t, then is there an exception or an error? – Roald Nov 07 '22 at 20:32

0 Answers0