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. Running operation at shutdown

Running operation at shutdown

Scheduled Pinned Locked Moved C#
4 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.
  • _ Offline
    _ Offline
    __DanC__
    wrote on last edited by
    #1

    Is there a way to run a potentially long operation at shutdown while (displaying progress and the ability to cancel to the user). Something like the synchronising folders that happens after the user has shutdown on a domain computer. I do not want to prevent shutdown or anything like that, just allow my application to finish any necessary processing as part of the shutdown process.

    M 1 Reply Last reply
    0
    • _ __DanC__

      Is there a way to run a potentially long operation at shutdown while (displaying progress and the ability to cancel to the user). Something like the synchronising folders that happens after the user has shutdown on a domain computer. I do not want to prevent shutdown or anything like that, just allow my application to finish any necessary processing as part of the shutdown process.

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! You'll have to subscribe to the (static) SessionEnding event of SystemEvents class and perform your operation in the corresponding event handler.

      Regards, mav -- Black holes are the places where God divided by 0...

      _ 1 Reply Last reply
      0
      • M mav northwind

        Hi! You'll have to subscribe to the (static) SessionEnding event of SystemEvents class and perform your operation in the corresponding event handler.

        Regards, mav -- Black holes are the places where God divided by 0...

        _ Offline
        _ Offline
        __DanC__
        wrote on last edited by
        #3

        Thanks, I have tried hooking that event and I can start the process when I receive the event but I only have a limited time (very short) to respond before Windows displays a dialog saying the aplpication has not closed (the one with the progress ticking down and "End Now" button), this would not be acceptable. I was hoping there was a way to run a long operation after the user session has ended but before the machine has shut down, such as the offline files synchronisation process in Windows.

        M 1 Reply Last reply
        0
        • _ __DanC__

          Thanks, I have tried hooking that event and I can start the process when I receive the event but I only have a limited time (very short) to respond before Windows displays a dialog saying the aplpication has not closed (the one with the progress ticking down and "End Now" button), this would not be acceptable. I was hoping there was a way to run a long operation after the user session has ended but before the machine has shut down, such as the offline files synchronisation process in Windows.

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          I don't know if there's a way to tell windows to postpone shutdown (perhaps there's a registry key for this), but right now I see only 2 alternatives: 1) Cancel the shutdown while your shutdown process is still running or 2) Start the shutdown process in a separate thread and don't cancel windows shutdown. But then your shutdown process can be aborted unexpectedly, so this might not be a good idea (depending on the real use case).

          Regards, mav -- Black holes are the places where God divided by 0...

          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