Loupe - Log - Monitor - Resolve
Gibraltar.Agent Namespace / Log Class / RegisterUIThread Method

In This Topic
    RegisterUIThread Method
    In This Topic
    Ensures the calling thread is configured for the Agent to manage exceptions. See Remarks for description of the rare circumstances this is needed.
    Syntax
    'Declaration
     
    
    Public Shared Sub RegisterUIThread() 
    public static void RegisterUIThread()
    Remarks

    This method may be called on a Windows UI thread just prior to calling any overload of Application.Run to ensure that the Loupe Agent registers as the event handler for Application.ThreadException events. Calling this method will register the Agent's event handler to record application exceptions on the calling thread even if CatchApplicationExceptions is configured to false. However, they may not be reported to the user, even if ReportErrorsToUser is configured to true, unless CatchApplicationExceptions is also true.

    In normal Windows applications, this method should not be needed (and in other application types this method is never needed) because the Agent will attempt to register for application exceptions automatically (if configured to do so). Automatic registration relies on the UI thread issuing a log message to Loupe (which may be through Trace), and the Agent inspects the thread's ApartmentState to distinguish likely UI threads from non-UI threads. The Agent will only automatically register for application exception events on threads created with a single-threaded apartment, not for threads created with the default multi-threaded apartment.

    Due to the design of the .NET runtime this event registration is lost every time Application.Run exits. Normally this is fine because the thread will then usually end and the entire application is typically exiting, but in advanced usage it is possible for a thread to continue and call Application.Run again. In such advanced use cases this method should be called each time Application.Run is about to be called if you want to use the Agent's handling of application exceptions.

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also