[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Detecting Windows Shutdown

Berger, Daniel

6/29/2005 3:10:00 PM

> -----Original Message-----
> From: Dennis Misener [mailto:dm@dymaxion.com]
> Sent: Wednesday, June 29, 2005 8:51 AM
> To: ruby-talk ML
> Subject: Detecting Windows Shutdown
>
>
> I needed to perform an orderly shutdown of a Webrick based Ruby
> application.
>
> I thought about trying to catch the WM_QUERYENDSESSION
> message which is
> sent to all programs when a request to shutdown Windows is made, in
> order to execute some code before Windows exits.
>
> Does anyone know how to do that in Ruby?
>
> Is it even possible?

Since Windows tries to shutdown all applications before shutting itself
down (I think), you ought to be able to just add an at_exit handler to
your application to do what you want.

See Kernel#at_exit.

However, it is my opinion that any Webrick based Ruby application (i.e.
server) should probably be run as a Service. If you decide to do this,
and you use the win32-service package, just define the exit behavior in
Daemon#service_stop and/or Daemon#service_shutdown methods.

Regards,

Dan