Event/function when Runtime Close for any reason

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
andrea
Posts: 72
Joined: Tue Dec 11, 2012 5:44 am

Event/function when Runtime Close for any reason

Post by andrea »

Hi,

I would like to reset a tag (so PLC variable) when the application closes for any reason (ALT + F4, task manager, power off the panel pc or the entire machine).
Where could I write this code?

Thank you

User avatar
Edmund
Posts: 92
Joined: Thu Nov 29, 2012 2:27 pm

Re: Event/function when Runtime Close for any reason

Post by Edmund »

Hi!

There is no built in function/event that occurs when the application is closed, but you can script your own (ONLY FOR PC TARGET!).

E.g.

Create a scriptmodule and paste the following code inside of it.

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
    
    
    public partial class ScriptModule1
    {
	
		private System.Windows.Application application;
		private bool init = false;
	
		public void ListenForApplicationEvent()
		{
			if(!init)
			{
				application = System.Windows.Application.Current;
				application.Exit += new System.Windows.ExitEventHandler(AppExit);
				init = true;
			}
		}
		
		private void AppExit(object sender, System.Windows.ExitEventArgs e)
		{
			// Do whatever you want here :)
			MessageBox.Show("Closing");
		}
    }
}
And from any screen that is being used in runtime (best would the the start screen for the project), it´s alright if the screen is opened several times because in the script module is a memory (init) that handles that.

Code: Select all


		void Screen1_Opened(System.Object sender, System.EventArgs e)
		{
			Globals.ScriptModule1.ListenForApplicationEvent();
		}
Now the AppExit function is being fired at closing and you can do what ever you want with it.
Edmund Andersson

AITECH AB

Part of Beijer Integrator Group

Post Reply