Page 1 of 1
Event/function when Runtime Close for any reason
Posted: Tue Nov 26, 2013 5:28 am
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
Re: Event/function when Runtime Close for any reason
Posted: Tue Nov 26, 2013 9:22 am
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.