1

I want to stop my C# application from running after the user has clicked shut down of computer so any idea how to do it?

1 Answer 1

8

you can use CloseReason.WindowsShutDown for this purpose inside the form closing event.

if (e.CloseReason != CloseReason.WindowsShutDown)
{
    e.Cancel = true;
}
else
{
    e.Cancel = false;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.