Optimization .NET abnormal treatment

xiaoxiao2021-03-06  15

Understanding is abnormal

N Most software systems are not 100% reliable!

n To stand at an abnormality that may have an angle to write an exception handler, and the procedure may have an error.

n Establish a good exception handling strategy

Handling unpredictable abnormalities

n Ensure that all programs have used try-catch

N of all the abnormalities in Catch

N abnormal processing technology

N record exception

n Record an abnormality in the file

n Record an exception in the database

N record an abnormality in EventLog

n Send Email Notification Experience

When n abnormality is generated, use the user-friendly method to notify the user.

Global abnormal treatment

Application.ThreadException event, only in the main thread

When an unrecorded thread occurs, the event allows the application to handle an exception when receiving the thread abnormality from a window process. Attach your event handler to the ThreadException event to process the exception. The appropriate event handler does not terminate the thread and allows the application to continue.

Abnormality in Workerthreads

n When writing multithreaded code, you must consider an exception that appears in the working thread.

n Use try-catch in the port of thread

n Use DELGATE or other way to make an exception notification to the main thread

Abnormal handling block

N Publisher / Subscriber design pattern

n Download exception handler block http://www.microsoft.com/downloads/details.aspx?familyid=8ca8eb6e-6f4a-43df-adeb-8f22ca173e02&displaylang=en

n compilation project

n Add reference to new projects

n Introduced Name Space Microdoft.ApplicationBlock.exceptionManagement

N Use exceptionManager.publish () to issue an exception

n Configure App.config file Enable exception management

n Configuring some information in .config files to add their own exception handling modules

Type = "Microsoft.ApplicationBlocks.exceptionManagement.defaultpublisher" logname = "Northwind Exceptions Log"

ApplicationName = "Northwind Traders Orders" />

转载请注明原文地址:https://www.9cbs.com/read-47943.html

New Post(0)