How can I release an Unhandled ErrorHandler

I am attempting to pass the value of a variable called glInitials from my main program to my UnhandledErrorHandler function in a linked Class Library to be included in file naming for an attachment that will be sent to my developers.  We have no problem passing glInitials but until a user completes my login form glInitials is set to nothing.

I want to continue loading my UnhandledErrorHandler on startup but I also want to be able to "re-initialize" the same Handler with updated glInitials after the login.

Can I simply create a new entry upon login as I do on startup or do I need to release (if I can) the ErrorHandler and then initialize it again ??

Please help.  Thanks in advance.
Phil Tate
TSFLLCAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Apparantly, the AddHandler method in your class already first removes the handler before adding it again. These lines
        RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler
        AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
are doing the job if you have not written it.
0
 
CodeCruiserCommented:
This description does not make any sense to me. Is the unhandlederrorhandler another class? Is it written by you?
0
 
Bob LearnedCommented:
Yeah, I agree that question makes no sense, but I am curious to find out what it means...
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
TSFLLCAuthor Commented:
Yes, the unhandlederrorhandler is IN another class.  I have both an unhandled and handled errorhandler in a separate class library.

I'm initially loading the unhandlederrorhandler on startup of my project, passing my initials (PT) to the errorhandler.  But when the user logs in, I want to re-initialize the errorhandler with their initials.  I use the intials in the creation of a .png that is included as an attachment (ex. - PT_Unhandled24155.png).

Because I didn't get any postings yesterday I went ahead and just set UnhandledErrorManager.AddHandler("PT") on startup and then after logging in I re-enter the line UnhandledErrorManager.AddHandler(trim(glInitials)).  In testing I found that if I did not enter the 2nd entry of the handler that the passing of glInitials remained "PT".

I hope that makes sense now.  Again, will I have a problem with setting the handler twice? Or should I do something different?

Thanks guys.
0
 
Bob LearnedConnect With a Mentor Commented:
With multi-cast event handlers, you can attach many handlers to the same event, but only careful study and usage will tell you whether you will have a problem with two event handlers to the same issue.  To be safe, I would remove the first event handler when attaching the second event handler.
0
 
TSFLLCAuthor Commented:
That's what I do not know how to do.  How can I 'remove/release/dispose' of the first event handler?
0
 
Bob LearnedCommented:
The reverse for AddHandler is RemoveHandler.
0
 
TSFLLCAuthor Commented:
Please excuse my ignorance.  This is new territory for me.  Because of that I think I was too close to it to see the reverse.   :)

I didn't write this errorhandler and it does not have a RemoveHandler in it.  I've been searching for a custom RemoveHandler....with no luck.  I also see that you can use, although I don't know if appropriate in this situation.....   RemoveHandler Object As Event, Object As Delegate when I highlight the word RemoveHandler.  However I'm not associating it with an event.  Am I?

What can I do?

Sincerely!
Phil Tate
0
 
TSFLLCAuthor Commented:
Is it as simple as adding the additional Public Shared Sub [RemoveHandler] into the UnhandledException class below?
    Public Shared Sub [AddHandler](ByVal xString As String)
        '-- get value of glInitials from main program for use with file names and system.random
        _UserInitials = Trim(xString)
        '-- attempt to load optional settings from .config file
        LoadConfigSettings()
 
        '-- track the parent assembly that set up error handling
        '-- need to call this NOW so we set it appropriately; otherwise
        '-- we may get the wrong assembly at exception time!
        ParentAssembly()
 
        '-- for winforms applications
        RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler
        AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
 
    End Sub
 
    Public Shared Sub [RemoveHandler]()
        '-- for winforms applications
        RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler
 
    End Sub

Open in new window

0
 
TSFLLCAuthor Commented:
Nasir,

I wish I had greater experience with this.  You are so right.  As I was adding RemoveHandler I was looking at the AddHandler code and it did not even dawn on me that it is performing cleanup within itself.

Perfect.

Thanks to both of you.  I couldn't do without EE.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.