Detect Shutdown from .NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adnan Hebibovic

    #1

    Detect Shutdown from .NET

    Hello developers

    How can I detect Windows shutdown from .NET and I mean clean .NET not
    catching the events with Win32 API ...

    Thanks


  • AMercer

    #2
    RE: Detect Shutdown from .NET

    Try handling the Microsoft.Win32 .SessionEnded event.

    "Adnan Hebibovic" wrote:
    [color=blue]
    > Hello developers
    >
    > How can I detect Windows shutdown from .NET and I mean clean .NET not
    > catching the events with Win32 API ...
    >
    > Thanks
    >
    >
    >[/color]

    Comment

    • Adnan Hebibovic

      #3
      Re: Detect Shutdown from .NET

      When the form is minimized to systray there is no Win32.SessionEn ded event
      ....

      Thanks
      "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
      news:AF974A9D-D2A1-41B6-8317-D64386646ABE@mi crosoft.com...[color=blue]
      > Try handling the Microsoft.Win32 .SessionEnded event.
      >
      > "Adnan Hebibovic" wrote:
      >[color=green]
      >> Hello developers
      >>
      >> How can I detect Windows shutdown from .NET and I mean clean .NET not
      >> catching the events with Win32 API ...
      >>
      >> Thanks
      >>
      >>
      >>[/color][/color]


      Comment

      • AMercer

        #4
        Re: Detect Shutdown from .NET

        Your first post asked how to "detect Windows shutdown". My response answered
        that. I just tried it out, and it worked (although I used session ending
        vice session ended). I run my program, I try to shut down windows, and the
        event fires. Your second post asks about minimizing. For that, you should
        handle the form's resize event and check the form property WindowState. If
        it is FormWindowState .Minimized, then the window is minimized.

        Windows shutdown and minimizing a window are different things. What exactly
        are you trying to detect?

        "Adnan Hebibovic" wrote:
        [color=blue]
        > When the form is minimized to systray there is no Win32.SessionEn ded event
        > ....
        >
        > Thanks
        > "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
        > news:AF974A9D-D2A1-41B6-8317-D64386646ABE@mi crosoft.com...[color=green]
        > > Try handling the Microsoft.Win32 .SessionEnded event.
        > >
        > > "Adnan Hebibovic" wrote:
        > >[color=darkred]
        > >> Hello developers
        > >>
        > >> How can I detect Windows shutdown from .NET and I mean clean .NET not
        > >> catching the events with Win32 API ...
        > >>
        > >> Thanks
        > >>
        > >>
        > >>[/color][/color]
        >
        >
        >[/color]

        Comment

        • Kevin Yu [MSFT]

          #5
          Re: Detect Shutdown from .NET

          Hi,

          I think Adnan might be asking that when he minimized a window to the system
          tray, the SessionEnded event is not fired. Right?

          I have tried it on my machine, and it works fine under any circumstances.
          Please try my code in a new windows application.

          private void Form1_Load(obje ct sender, System.EventArg s e)
          {
          Microsoft.Win32 .SystemEvents.S essionEnded +=new
          Microsoft.Win32 .SessionEndedEv entHandler(Syst emEvents_Sessio nEnded);
          this.Resize +=new EventHandler(Fo rm1_Resize);
          }

          private void SystemEvents_Se ssionEnded(obje ct sender,
          Microsoft.Win32 .SessionEndedEv entArgs e)
          {
          MessageBox.Show ("End");
          }

          private void Form1_Resize(ob ject sender, EventArgs e)
          {
          if(this.WindowS tate == FormWindowState .Minimized)
          {
          this.ShowInTask bar = false;
          this.notifyIcon 1.Visible=true;
          }
          else
          this.ShowInTask bar = true;
          this.notifyIcon 1.DoubleClick+= new EventHandler(no tifyIcon1_Doubl eClick);
          }

          private void notifyIcon1_Dou bleClick(object sender, EventArgs e)
          {
          this.WindowStat e = FormWindowState .Normal;
          this.notifyIcon 1.Visible = false;
          }

          HTH.

          Kevin Yu
          =======
          "This posting is provided "AS IS" with no warranties, and confers no
          rights."

          Comment

          • Adnan Hebibovic

            #6
            Re: Detect Shutdown from .NET

            Thanks I see now where is the problem with my code.

            "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> wrote in message
            news:PP68AjaMFH A.2668@TK2MSFTN GXA03.phx.gbl.. .[color=blue]
            > Hi,
            >
            > I think Adnan might be asking that when he minimized a window to the
            > system
            > tray, the SessionEnded event is not fired. Right?
            >
            > I have tried it on my machine, and it works fine under any circumstances.
            > Please try my code in a new windows application.
            >
            > private void Form1_Load(obje ct sender, System.EventArg s e)
            > {
            > Microsoft.Win32 .SystemEvents.S essionEnded +=new
            > Microsoft.Win32 .SessionEndedEv entHandler(Syst emEvents_Sessio nEnded);
            > this.Resize +=new EventHandler(Fo rm1_Resize);
            > }
            >
            > private void SystemEvents_Se ssionEnded(obje ct sender,
            > Microsoft.Win32 .SessionEndedEv entArgs e)
            > {
            > MessageBox.Show ("End");
            > }
            >
            > private void Form1_Resize(ob ject sender, EventArgs e)
            > {
            > if(this.WindowS tate == FormWindowState .Minimized)
            > {
            > this.ShowInTask bar = false;
            > this.notifyIcon 1.Visible=true;
            > }
            > else
            > this.ShowInTask bar = true;
            > this.notifyIcon 1.DoubleClick+= new EventHandler(no tifyIcon1_Doubl eClick);
            > }
            >
            > private void notifyIcon1_Dou bleClick(object sender, EventArgs e)
            > {
            > this.WindowStat e = FormWindowState .Normal;
            > this.notifyIcon 1.Visible = false;
            > }
            >
            > HTH.
            >
            > Kevin Yu
            > =======
            > "This posting is provided "AS IS" with no warranties, and confers no
            > rights."
            >[/color]


            Comment

            • Kevin Yu [MSFT]

              #7
              Re: Detect Shutdown from .NET

              You're welcome, Adnan.

              Thanks for sharing your experience with all the people here. If you have
              any questions, please feel free to post them in the community.

              Kevin Yu
              =======
              "This posting is provided "AS IS" with no warranties, and confers no
              rights."

              Comment

              Working...