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
  1. Home
  2. General Programming
  3. C#
  4. Questions About Form Closing Event In winform

Questions About Form Closing Event In winform

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 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.
  • J Offline
    J Offline
    jdnx
    wrote on last edited by
    #1

    I want to write a winform program to implement following behaviour when the program exits,I will write some log infomation in a log file so I write some code in Form_Closing Function,It works fine when I click X on the window.But when I shutdown the computer before I close the program,It seems Form_Closing Event is not fired,so the log information is not saved into file.I checked many articles on MSDN And Google,It all says,this event will be triggered when shutting down the computer,I also tried to handle the WM_QUERYENDSESSION message,it did not work either. Can Anyone give some suggestions and help? thanks

    L 1 Reply Last reply
    0
    • J jdnx

      I want to write a winform program to implement following behaviour when the program exits,I will write some log infomation in a log file so I write some code in Form_Closing Function,It works fine when I click X on the window.But when I shutdown the computer before I close the program,It seems Form_Closing Event is not fired,so the log information is not saved into file.I checked many articles on MSDN And Google,It all says,this event will be triggered when shutting down the computer,I also tried to handle the WM_QUERYENDSESSION message,it did not work either. Can Anyone give some suggestions and help? thanks

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, AFAIK you should: - have a "LogClosing" method that logs what needs to be logged; - have that called by the SystemEvents.SessionEnding handler; - have it also called by the Form.FormClosing handler; - implement some protection so it only executes once (as FormClosing may or may not fire on session end) :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.


      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