exit-handler

How do I write an exit handler for an F# application?

核能气质少年 提交于 2019-12-23 08:39:11
问题 Subject says it all. I want some code to run if my application is terminated by, say, ^C. 回答1: Use AppDomain.ProcessExit (http://msdn.microsoft.com/en-us/library/system.appdomain.processexit.aspx): System.AppDomain.CurrentDomain.ProcessExit(fun _ -> ...) 回答2: See code below. To handle Ctrl-C in a console app, use the Console.CancelKeyPress event. // does not work - no exception on Ctrl-C //System.AppDomain.CurrentDomain.UnhandledException.Add( // fun _ -> printfn "app is about to die") System

Does Application.ApplicationExit event work to be notified of exit in non-Winforms apps?

烂漫一生 提交于 2019-12-04 09:41:13
问题 Our code library needs to be notified when the application is exiting. So we have subscribed to the System.Window.Forms.Application.ApplicationExit event. This works nicely for Winforms apps, but does it also work for other types of applications such as console apps, services, and web apps (such as ASP.NET)? The namespace would suggest that it doesn't, and it presumably gets raised when Application.Exit() is called (explicitly or implictly), which may not be correct to call for these other

Does Application.ApplicationExit event work to be notified of exit in non-Winforms apps?

孤街醉人 提交于 2019-12-03 03:40:29
Our code library needs to be notified when the application is exiting. So we have subscribed to the System.Window.Forms.Application.ApplicationExit event. This works nicely for Winforms apps, but does it also work for other types of applications such as console apps, services, and web apps (such as ASP.NET)? The namespace would suggest that it doesn't, and it presumably gets raised when Application.Exit() is called (explicitly or implictly), which may not be correct to call for these other cases. Is there some other event which would be better in these other cases or which would be more