0

I have program , start when windows start. Users have to open this app and they can’t close it. When users open it, a variable in sql will be true, but I want before shutdown windows this variable will be false. How this possible? Users can’t close the app: e.Cancel = true; but I want before shutdown , variable in database will be false. thanks

Dan D.
  • 73,243
  • 15
  • 104
  • 123
tara1367
  • 7
  • 7

1 Answers1

0

You should catch event on windows shutting down. And in handler you can exec sql query, that change your field in table.

Here you can get more information about windows shutting down: How to detect Windows shutdown or logoff

EDIT

You can use this code in handler of FormClosing event:

if (e.CloseReason == CloseReason.WindowsShutDown)
{
    // do some sql stuff
}
else
{
    e.Cancel = true;
}

When Windows is shutting down it send close signal to all applications.

Community
  • 1
  • 1
Indian
  • 529
  • 1
  • 12
  • 25
  • thanks for reply. I saw the link. but notice in my program users can't close application. by this code in OnClosing event:e.cancel=true; where can I write some code before windows force close my app and shutdown? – tara1367 Dec 02 '14 at 10:07