?
Solved

How can I release an Unhandled ErrorHandler

Posted on 2009-04-20
10
Medium Priority
?
257 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:TSFLLC
  • 5
  • 3
  • 2
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24192212
This description does not make any sense to me. Is the unhandlederrorhandler another class? Is it written by you?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24193076
Yeah, I agree that question makes no sense, but I am curious to find out what it means...
0
 

Author Comment

by:TSFLLC
ID: 24193903
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 800 total points
ID: 24194039
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
 

Author Comment

by:TSFLLC
ID: 24194145
That's what I do not know how to do.  How can I 'remove/release/dispose' of the first event handler?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24194206
The reverse for AddHandler is RemoveHandler.
0
 

Author Comment

by:TSFLLC
ID: 24194803
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
 

Author Comment

by:TSFLLC
ID: 24194923
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1200 total points
ID: 24195056
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
 

Author Comment

by:TSFLLC
ID: 24195185
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question