WinCC OA C# API: finalize program when stopping manager

Discussion about recent product features & solutions!
2 posts • Page 1 of 1
Karel@RCM
Posts:2
Joined: Mon Nov 06, 2017 11:19 am

WinCC OA C# API: finalize program when stopping manager

Post by Karel@RCM »

Dear all,

Recently I started building a WinCC OA manager with the C# API released in version 15.

I called my manager "WCCOASimitManager". This manager has to control a TCP/IP client for a remote interface connection to another application, in my case SIMIT.

In order to provide a stable application, the manager needs to disconnect the TCP/IP client when I stop (or kill) the manager in the WinCC OA Console, otherwise SIMIT will freeze.

When I stop my manager, 4 events are logged in the event logger. I hoped this would provide me answers. I'll guess I have to listen for the "SIGTERM" event in my C# application, but I couldn't find any information in the documentation about this event.

I would expect to program something like this:

OaManager.ManagerStopped += (vcsender, vce) =>
{
Client.proxy.SimDisconnect(clientID, out result, out errormessage); // Disconnect the SIMIT Client
};

Any ideas on how I can implement a deconstructor/termination event into my C# application when the manager is stopped?

Thanks in advance!

Regards,

Karel van Leeuwe

Code: Select all

WCCILpmon    (1), 2018.04.18 13:53:55.493, SYS,  INFO,       25/pmon, Got STOP command (SIGTERM) from 127.0.0.1, stopping the manager WCCOASimitManager(1) at index 6
WCCILpmon    (1), 2018.04.18 13:53:55.504, SYS,  INFO,       17/pmon, Stopping Manager WCCOASimitManager(1) with signal SIGTERM
WCCILevent   (0), 2018.04.18 13:53:55.529, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Api -num 1 CONN: 1), Connection reset by peer (10054)
WCCILdata    (0), 2018.04.18 13:53:55.529, SYS,  WARNING,    39, Connection lost, MAN: (SYS: 1 Api -num 1 CONN: 1), Connection reset by peer (10054)

Karel@RCM
Posts:2
Joined: Mon Nov 06, 2017 11:19 am

Re: WinCC OA C# API: finalize program when stopping manager

Post by Karel@RCM »

The following procedure provided a possible solution!

Code: Select all

class Program
    {
        static void Main(string[] args)
        {
            // Handle the ProcessExit event to know when the process is exiting.
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
        }
        static void CurrentDomain_ProcessExit(object sender, EventArgs e)
        {
            Console.WriteLine("Finalize program");
        }
    }
}

2 posts • Page 1 of 1