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
Event/function when Runtime Close for any reason
Re: Event/function when Runtime Close for any reason
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.
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.
Now the AppExit function is being fired at closing and you can do what ever you want with it.
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");
}
}
}
Code: Select all
void Screen1_Opened(System.Object sender, System.EventArgs e)
{
Globals.ScriptModule1.ListenForApplicationEvent();
}