How can we help you today?
Application doesn't exit after adding the Loupe Agent Print
Modified on: Thu, Jul 17, 2014 at 5:05 PM
When you add the Loupe Agent to your application and it gets initialized (either because you called Log.StartSession() or wrote any log or metric data to it) then the application never exits. For console applications it will appear to hang and never return while WinForms and WPF applications may have all of their windows close but will still show in the task manager
The Loupe Agent has its own dedicated threads for writing out data. This lets it write data asynchronously and efficiently without impacting your application. But, these threads will keep the .NET application domain running even if your main threads have exited. To get the process to exit, you need to be sure to call Log.EndSession() before your normal main thread exits.
EndSession puts the Loupe Agent in shutdown mode. In this mode it switches to synchronous logging (flushing every message to disk as they are written), disables some background processes that might slowdown the shutdown process (like automatic session data transmission and performance metric gathering) and records the session as exiting normally (unless you tell it the session has crashed).
If you follow the integration instructions for your application type they show you were to place both a StartSession and EndSession call to ensure the agent starts as soon as possible and goes into shutdown mode as close to the end of your process lifecycle as possible.
Don't forget to handle the exception exit case - you often will want to wrap your top level method in a Try/Catch/Finally structure and put an EndSession call in the Finally block so you can be assured it will be invoked in every circumstance.
Did you find it helpful? Yes NoSend feedback