locked
Application's close event and Windows logout RRS feed

  • Question

  • It doesn't seem like a C# application's close event is processed on Windows logout. I.e. As a test, i've placed a StreamWriter in an aplication's close event to write a single line of text, but the file is never written to disc.

    Is there another way to guarantee the close event is processed before windows logout?
    Monday, November 3, 2008 4:02 PM

Answers

  • try FormClosing event.
    if you found answer for your question , always click the 'Mark as Answer' button on the respective answers.
    Monday, November 3, 2008 4:12 PM
  • Simple Example, hope this is what you are looking for

    using Microsoft.Win32;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                SystemEvents.SessionEnded += new SessionEndedEventHandler(SystemEvents_SessionEnded);
            }


            public void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
            {
                MessageBox.Show("I am Working");



            }
        }
    }

    Edit: Please make sure you use close event to write log as well since user closes your application manually too

    Arjun Paudel
    Monday, November 3, 2008 4:17 PM

All replies

  • try FormClosing event.
    if you found answer for your question , always click the 'Mark as Answer' button on the respective answers.
    Monday, November 3, 2008 4:12 PM
  • Simple Example, hope this is what you are looking for

    using Microsoft.Win32;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                SystemEvents.SessionEnded += new SessionEndedEventHandler(SystemEvents_SessionEnded);
            }


            public void SystemEvents_SessionEnded(object sender, SessionEndedEventArgs e)
            {
                MessageBox.Show("I am Working");



            }
        }
    }

    Edit: Please make sure you use close event to write log as well since user closes your application manually too

    Arjun Paudel
    Monday, November 3, 2008 4:17 PM