0

I hide a application like this:

class Program {    

    [DllImport("kernel32.dll")]
    static extern IntPtr GetConsoleWindow();
    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    static int SW_SHOW = 5;
    static int SW_HIDE = 0;

    public static void Main(string[] args)
    { 

        var handle = GetConsoleWindow();
        //Hide
        ShowWindow(handle, SW_HIDE);
        //And more...
    }       
}

My CurrentDomain_ProcessExit and ConsoleEventCallback events are not working when I hide the program.

I want to run some codes when Windows is shutting down.

Which way do I have to go?(This application is Console Application)

  • 3
    are You sure want GUI application? Maybe kind of service? – Jacek Cz Oct 29 '17 at 13:08
  • Like a service yes. I can't use GUI because it's too late. I already have 500 code lines and it was hard to code. I don't have time. – Abdulkadir Can Kinsiz Oct 29 '17 at 13:13
  • possible duplicate of https://stackoverflow.com/questions/6799955/how-to-detect-windows-shutdown-or-logoff – Dale Oct 29 '17 at 13:17
  • 2
    Possible duplicate of [How to detect Windows shutdown or logoff](https://stackoverflow.com/questions/6799955/how-to-detect-windows-shutdown-or-logoff) – Dale Oct 29 '17 at 13:17

0 Answers0