Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Please Help me!! My pc is not going to shutdown when application is running

Please Help me!! My pc is not going to shutdown when application is running

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Irfan Kothari
    wrote on last edited by
    #1

    Hello friends, I have developed one application, in that if user clicks on close button the application is minimize to system tray if user want to close the application than user will right click on system tray icon and click on close buton. Now problem is when my application is in system tray and if i am going to shutdown/restart/logoff my ocmputer than all processes is going close but after that nothing is happening. if i want to shutdown the computer than i have to close my application first can anyone having idea regarding this?? please help me as soon as possible any kind of help is appreciable thanks in advance Irfan Kothari

    S 1 Reply Last reply
    0
    • I Irfan Kothari

      Hello friends, I have developed one application, in that if user clicks on close button the application is minimize to system tray if user want to close the application than user will right click on system tray icon and click on close buton. Now problem is when my application is in system tray and if i am going to shutdown/restart/logoff my ocmputer than all processes is going close but after that nothing is happening. if i want to shutdown the computer than i have to close my application first can anyone having idea regarding this?? please help me as soon as possible any kind of help is appreciable thanks in advance Irfan Kothari

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Add the following code to your form. It filters the session end message and sets a flag that can be tested in the Closing event handler.

      protected override void WndProc(ref Message m)
      {
      if (m.Msg == 0x0011)//WM_QUERYENDSESSION
      // Allow the application to close, if the current session ends.
      this.allowClosing = true;

      base.WndProc(ref m);
      

      }


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      I 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Add the following code to your form. It filters the session end message and sets a flag that can be tested in the Closing event handler.

        protected override void WndProc(ref Message m)
        {
        if (m.Msg == 0x0011)//WM_QUERYENDSESSION
        // Allow the application to close, if the current session ends.
        this.allowClosing = true;

        base.WndProc(ref m);
        

        }


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        I Offline
        I Offline
        Irfan Kothari
        wrote on last edited by
        #3

        Hello stefan, i have found very simple solutuion to this problem. before your posting but than also thanks. whenever we click on shutdown it will call form closing event in the application and i have written following code in my form closing event. this.WindowState = FormWindowState.Minimized; this.Opacity = 1; this.ShowInTaskbar = false; if (this.FrmCloseFlg == false) { e.Cancel = true; } thats y my application is not going to exit instead it will be in minimize position. so i have used one boolean variable and use condition as follows if(!InSystemTray) { this.WindowState = FormWindowState.Minimized; this.Opacity = 1; this.ShowInTaskbar = false; if (this.FrmCloseFlg == false) { e.Cancel = true; } //UserCanceled = true; UserInfo.InSystemTray = true; } else { Application.Exit(); } The InSystemTray will set to false again whenever we manually clik on open context menu or double click tray icon ,whatever it is. is it simple na!!!!!:laugh: So we dont have a right to call any person an idiot ok buddy,be cool Regards, Irfan Kothari

        Y 1 Reply Last reply
        0
        • I Irfan Kothari

          Hello stefan, i have found very simple solutuion to this problem. before your posting but than also thanks. whenever we click on shutdown it will call form closing event in the application and i have written following code in my form closing event. this.WindowState = FormWindowState.Minimized; this.Opacity = 1; this.ShowInTaskbar = false; if (this.FrmCloseFlg == false) { e.Cancel = true; } thats y my application is not going to exit instead it will be in minimize position. so i have used one boolean variable and use condition as follows if(!InSystemTray) { this.WindowState = FormWindowState.Minimized; this.Opacity = 1; this.ShowInTaskbar = false; if (this.FrmCloseFlg == false) { e.Cancel = true; } //UserCanceled = true; UserInfo.InSystemTray = true; } else { Application.Exit(); } The InSystemTray will set to false again whenever we manually clik on open context menu or double click tray icon ,whatever it is. is it simple na!!!!!:laugh: So we dont have a right to call any person an idiot ok buddy,be cool Regards, Irfan Kothari

          Y Offline
          Y Offline
          Yustme
          wrote on last edited by
          #4

          Hi, He didn't called you an idiot. Its his signature :-D Like you got yours: "Regards, Irfan Kothari"

          I 1 Reply Last reply
          0
          • Y Yustme

            Hi, He didn't called you an idiot. Its his signature :-D Like you got yours: "Regards, Irfan Kothari"

            I Offline
            I Offline
            Irfan Kothari
            wrote on last edited by
            #5

            Sorry Guys, I have misunderstood it.:( ok anyways sorry once again :-D Regards, Irfan Kothari "Take Care Not Chances"

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups