Detecta cierre de sesion o apagado del equipo y no pide confirmacion de cierre: ya no impide/dificulta el apagado/reinicio del servidor

This commit is contained in:
Ernesto Abarca Ortiz 2018-08-07 15:01:08 +02:00
parent 30d4a47819
commit 828315fd94
1 changed files with 31 additions and 5 deletions

View File

@ -17,10 +17,29 @@ namespace LectorVerdnatura
private sdklector lector; private sdklector lector;
private database db; private database db;
private static int WM_QUERYENDSESSION = 0x11;
private static bool systemShutdown = false;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
//MessageBox.Show("Detectado queryendsession: logoff, shutdown, or reboot");
systemShutdown = true;
}
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
base.WndProc(ref m);
} //WndProc
public frmPrincipal() public frmPrincipal()
{ {
InitializeComponent(); InitializeComponent();
Process aProcess = Process.GetCurrentProcess(); Process aProcess = Process.GetCurrentProcess();
string aProcName = aProcess.ProcessName; string aProcName = aProcess.ProcessName;
if (Process.GetProcessesByName(aProcName).Length > 1) if (Process.GetProcessesByName(aProcName).Length > 1)
@ -96,16 +115,23 @@ namespace LectorVerdnatura
private void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e) private void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e)
{ {
DialogResult respuesta = MessageBox.Show("La aplicacion debe estar en marcha para recoger los fichajes!" + Environment.NewLine + "¿ Esta seguro de que desea cerrar la aplicacion ?", "Confirmacion", MessageBoxButtons.YesNo); if (! systemShutdown)
if (respuesta == DialogResult.No) {
e.Cancel = true; // Reset the variable because the user might cancel the shutdown.
systemShutdown = false;
DialogResult respuesta = MessageBox.Show("La aplicacion debe estar en marcha para recoger los fichajes!" + Environment.NewLine + "¿ Esta seguro de que desea cerrar la aplicacion ?", "Confirmacion", MessageBoxButtons.YesNo);
if (respuesta == DialogResult.No)
e.Cancel = true;
}
//e.Cancel = true; //e.Cancel = true;
//this.WindowState = FormWindowState.Minimized; //this.WindowState = FormWindowState.Minimized;
//frmPrincipal_Resize(this, null); //frmPrincipal_Resize(this, null);
} }
private void Salir_Click(object sender, EventArgs e) private void Salir_Click(object sender, EventArgs e)
{ {
this.notifyIcon1.Visible = false; this.notifyIcon1.Visible = false;